Class: TypographerHelper::Parsers::Basic

Inherits:
Object
  • Object
show all
Defined in:
lib/typographer/parsers/basic.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Basic

Returns a new instance of Basic.



5
6
7
# File 'lib/typographer/parsers/basic.rb', line 5

def initialize(options = {})
  @options = options.merge({})
end

Instance Method Details

#parse(string) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/typographer/parsers/basic.rb', line 9

def parse(string)
  #apostrophe

  string = string.gsub(//,'„')
  string.gsub!(//,'“')

  if (RUBY_VERSION > '1.9')
    string.gsub!(Regexp.new('(\p{Word})\'(\p{Word})'), '\1’\2')
  else
    string.gsub!(/(\w)'(\w)/, '\1’\2')
  end

  #russian quotes
  string = replace_quotes string, '«', '»', '„', '“', 'а-яА-Я'

  #english quotes
  string = replace_quotes string
  
  replaces.each do |replacement|
    string.gsub!(replacement[0], replacement[1])
  end
  
  string
end