Class: Krikri::Parser::Value
- Inherits:
-
Object
- Object
- Krikri::Parser::Value
- Defined in:
- lib/krikri/parser.rb
Overview
A generic parser value.
Interface to a single value node which can access typed data values (e.g. String, DateTime, etc…) parsed from a string, and provides access to child nodes and attributes.
Direct Known Subclasses
Instance Method Summary collapse
-
#[](name) ⇒ Object
Property accessor interface.
-
#attribute?(name) ⇒ Boolean
Queries whether ‘name` is an attribute of this node.
-
#attributes ⇒ Array<Symbol>
abstract
A list of attributes accessible on the node.
-
#child?(name) ⇒ Boolean
Queries whether ‘name` is a subproperty of this node.
-
#children ⇒ Array<Symbol>
abstract
A list of subproperties that can be passed back to #[] to access child nodes.
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing(method) ⇒ Object
-
#value ⇒ <#to_s>
abstract
Typed value for the property.
-
#values? ⇒ Boolean
abstract
True if this node has typed values accessible with #values.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
95 96 97 98 |
# File 'lib/krikri/parser.rb', line 95 def method_missing(name, *args, &block) return attribute(name) if attribute?(name) super end |
Instance Method Details
#[](name) ⇒ Object
Property accessor interface. Passes ‘name` to the local implementation of #get_child_nodes.
41 42 43 |
# File 'lib/krikri/parser.rb', line 41 def [](name) get_child_nodes(name) end |
#attribute?(name) ⇒ Boolean
Queries whether ‘name` is an attribute of this node
87 88 89 90 91 92 93 |
# File 'lib/krikri/parser.rb', line 87 def attribute?(name) begin attributes.include?(name) rescue NotImplementedError false end end |
#attributes ⇒ Array<Symbol>
Returns a list of attributes accessible on the node.
79 80 81 |
# File 'lib/krikri/parser.rb', line 79 def attributes raise NotImplementedError end |
#child?(name) ⇒ Boolean
Queries whether ‘name` is a subproperty of this node
49 50 51 |
# File 'lib/krikri/parser.rb', line 49 def child?(name) children.include?(name) end |
#children ⇒ Array<Symbol>
Returns a list of subproperties that can be passed back to #[] to access child nodes.
57 58 59 |
# File 'lib/krikri/parser.rb', line 57 def children raise NotImplementedError end |
#respond_to_missing(method) ⇒ Object
100 101 102 |
# File 'lib/krikri/parser.rb', line 100 def respond_to_missing(method, *) attribute?(method) || super end |
#value ⇒ <#to_s>
Returns typed value for the property.
64 65 66 |
# File 'lib/krikri/parser.rb', line 64 def value raise NotImplementedError end |
#values? ⇒ Boolean
Returns true if this node has typed values accessible with #values.
72 73 74 |
# File 'lib/krikri/parser.rb', line 72 def values? raise NotImplementedError end |