Class: Faml::StaticHashParser
- Inherits:
-
Object
- Object
- Faml::StaticHashParser
- Defined in:
- lib/faml/static_hash_parser.rb
Constant Summary collapse
- FAILURE_TAG =
:failure
- SPECIAL_ATTRIBUTES =
%w[id class data].freeze
Instance Attribute Summary collapse
-
#dynamic_attributes ⇒ Object
readonly
Returns the value of attribute dynamic_attributes.
-
#static_attributes ⇒ Object
readonly
Returns the value of attribute static_attributes.
Instance Method Summary collapse
-
#initialize ⇒ StaticHashParser
constructor
A new instance of StaticHashParser.
- #parse(text) ⇒ Object
- #walk(node) ⇒ Object
Constructor Details
#initialize ⇒ StaticHashParser
Returns a new instance of StaticHashParser.
11 12 13 14 |
# File 'lib/faml/static_hash_parser.rb', line 11 def initialize @static_attributes = {} @dynamic_attributes = {} end |
Instance Attribute Details
#dynamic_attributes ⇒ Object (readonly)
Returns the value of attribute dynamic_attributes.
9 10 11 |
# File 'lib/faml/static_hash_parser.rb', line 9 def dynamic_attributes @dynamic_attributes end |
#static_attributes ⇒ Object (readonly)
Returns the value of attribute static_attributes.
9 10 11 |
# File 'lib/faml/static_hash_parser.rb', line 9 def static_attributes @static_attributes end |
Instance Method Details
#parse(text) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/faml/static_hash_parser.rb', line 16 def parse(text) builder = ::Parser::Builders::Default.new builder.emit_file_line_as_literals = false parser = ::Parser::CurrentRuby.new(builder) parser.diagnostics.consumer = nil buffer = ::Parser::Source::Buffer.new('(faml)') buffer.source = text walk(parser.parse(buffer)) rescue ::Parser::SyntaxError false end |
#walk(node) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/faml/static_hash_parser.rb', line 28 def walk(node) catch(FAILURE_TAG) do walk_hash(node) return true end false end |