Class: It::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/it/parser.rb

Constant Summary collapse

INTERPOLATION_REGEXP =
/%\{[^{}}]+\}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, options) ⇒ Parser

Returns a new instance of Parser.



7
8
9
10
# File 'lib/it/parser.rb', line 7

def initialize(string, options)
  self.string = string
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/it/parser.rb', line 3

def options
  @options
end

#stringObject

Returns the value of attribute string.



3
4
5
# File 'lib/it/parser.rb', line 3

def string
  @string
end

Instance Method Details

#processObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/it/parser.rb', line 12

def process
  handle_pluralization
  escape_string

  # For deep nesting, we repeat the process until we have no interpolations anymore
  while has_interpolation?
    self.string.gsub!(INTERPOLATION_REGEXP) do |interpolation|
      Interpolation.new(interpolation, options).process
    end
  end
  string.html_safe
end