Class: Serega::SeregaPlugins::StringModifiers::ParseStringModifiers
- Inherits:
-
Object
- Object
- Serega::SeregaPlugins::StringModifiers::ParseStringModifiers
- Defined in:
- lib/serega/plugins/string_modifiers/parse_string_modifiers.rb
Overview
Modifiers parser
Class Method Summary collapse
-
.parse(fields) ⇒ Hash
Parses string modifiers.
Class Method Details
.parse(fields) ⇒ Hash
Parses string modifiers
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/serega/plugins/string_modifiers/parse_string_modifiers.rb', line 42 def parse(fields) res = {} attribute = +"" char = +"" path_stack = nil fields = StringIO.new(fields) while fields.read(1, char) case char when "," add_attribute(res, path_stack, attribute, FROZEN_EMPTY_HASH) when ")" add_attribute(res, path_stack, attribute, FROZEN_EMPTY_HASH) path_stack&.pop when "(" name = add_attribute(res, path_stack, attribute, {}) (path_stack ||= []).push(name) if name else attribute.insert(-1, char) end end add_attribute(res, path_stack, attribute, FROZEN_EMPTY_HASH) res end |