Class Texy::Modules::QuickCorrect
In: lib/texy/modules/quick_correct.rb
Parent: Base

Automatic replacements module class

Methods

init   line_post_process   new  

Attributes

dash  [RW]  dash (–)
double_quotes  [RW]  left & right double quote („ “)
single_quotes  [RW]  left & right single quote (‚ ‘)

Public Class methods

[Source]

# File lib/texy/modules/quick_correct.rb, line 47
            def initialize(texy)
                super

                self.double_quotes = ['„', '“']
                self.single_quotes = ['‚', '‘']
                self.dash = '–'
            end

Public Instance methods

Module initialization.

[Source]

# File lib/texy/modules/quick_correct.rb, line 56
            def init
                @pairs = [
                    # double ""
                    [/([^"\w]|^)"(?!\ |")(.+?[^\ "])"(?!")()/, "\\1#{double_quotes[0]}\\2#{double_quotes[1]}"],

                    # single ''
                    [/([^'\w]|^)'(?!\ |')(.+?[^\ '])'(?!')()/, "\\1#{single_quotes[0]}\\2#{single_quotes[1]}"],

                    # ellipsis ...
                    [/(\S|^)\ ?\.{3}/, '\1…'],

                    # en dash -
                    [/(\d| )-(\d| )/, "\\1#{dash}\\2"],

                    # en dash ,-
                    [/,-/, ",#{dash}"],

                    # date 23. 1. 1978
                    [/([^\d]|^)(\d{1,2}\.)\ (\d{1,2}\.)\ (\d\d)/, '\1\2 \3 \4'],

                    # date 23. 1.
                    [/([^\d]|^)(\d{1,2}\.)\ (\d{1,2}\.)/, '\1\2 \3'],

                    # en dash --
                    [/\ --\ /, " #{dash} "],

                    # right arrow ->
                    [/\ ->\ /, ' → '],

                    # left arrow ->
                    [/\ <-\ /, ' ← '],

                    # left right arrow <->
                    [/\ &lt;-&gt;\ /, ' &#8596; '],

                    # dimension sign x
                    [/(\d+)\ ?x\ ?(\d+)\ ?x\ ?(\d+)/, '\1&#215;\2&#215;\3'],

                    # dimension sign x
                    [/(\d+) ?x ?(\d+)/, '\1&#215;\2'],

                    # 10x
                    [/(\d)x(?= |,|.|$)/, '\1&#215;'],

                    # trademark  (TM)
                    [/(\S ?)\(TM\)/i, '\1&#8482;'],

                    # registered (R)
                    [/(\S ?)\(R\)/i, '\1&#174;'],

                    # copyright  (C)
                    [/\(C\)( ?\S)/i, '&#169;\1'],

                    # (phone) number 1 123 123 123
                    [/(\d{1,3})\ (\d{3})\ (\d{3})\ (\d{3})/, '\1&#160;\2&#160;\3&#160;\4'],

                    # (phone) number 1 123 123
                    [/(\d{1,3})\ (\d{3})\ (\d{3})/, '\1&#160;\2&#160;\3'],

                    # number 1 123
                    [/(\d{1,3})\ (\d{3})/, '\1&#160;\2'], # number 1 123

                    # space between number and word
                    [/([\ \.,\-\+]|^)(\d+)([#{HASH_NC}]*)\ ([#{HASH_NC}]*)(\w)/, '\1\2\3&#160;\4\5'],

                    # space between preposition and word
                    # (rane) TODO: the preposition list should be configurable
                    [/(^|[^0-9\w])([#{HASH_NC}]*)([ksvzouiKSVZOUIA])([#{HASH_NC}]*)\ ([#{HASH_NC}]*)([0-9\w])/,
                        '\1\2\3\4&#160;\5\6'],
                ]
            end

[Source]

# File lib/texy/modules/quick_correct.rb, line 128
            def line_post_process(text)
                return text unless allowed

                @pairs.each do |(from, to)|
                    text.gsub!(from, to)
                end

                text
            end

[Validate]