Class: It::Parser
- Inherits:
-
Object
- Object
- It::Parser
- Defined in:
- lib/it/parser.rb
Overview
Parses the string and replaces all interpolations accordingly.
Constant Summary collapse
- INTERPOLATION_REGEXP =
/%\{[^{}]+\}/.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(string, options) ⇒ Parser
constructor
A new instance of Parser.
- #process ⇒ Object
Constructor Details
#initialize(string, options) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 |
# File 'lib/it/parser.rb', line 12 def initialize(string, ) @string = string @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/it/parser.rb', line 4 def @options end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
4 5 6 |
# File 'lib/it/parser.rb', line 4 def string @string end |
Class Method Details
.backend_options(options) ⇒ Object
8 9 10 |
# File 'lib/it/parser.rb', line 8 def self.() .with_indifferent_access.slice(:default, :locale, :scope) end |
Instance Method Details
#process ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/it/parser.rb', line 17 def process handle_pluralization escape_string # For deep nesting, we repeat the process until we have no interpolations anymore while contains_interpolation? string.gsub!(INTERPOLATION_REGEXP) do |interpolation| Interpolation.call(interpolation, ) end end string.html_safe end |