Class: ModelXML::BlockParser
- Inherits:
-
Object
- Object
- ModelXML::BlockParser
- Defined in:
- lib/model_xml/block_parser.rb
Instance Attribute Summary collapse
-
#field_set ⇒ Object
readonly
Returns the value of attribute field_set.
Class Method Summary collapse
Instance Method Summary collapse
- #field(*args) ⇒ Object
-
#initialize ⇒ BlockParser
constructor
A new instance of BlockParser.
- #method_missing(*args) ⇒ Object
Constructor Details
#initialize ⇒ BlockParser
Returns a new instance of BlockParser.
17 18 19 |
# File 'lib/model_xml/block_parser.rb', line 17 def initialize @field_set = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
34 35 36 |
# File 'lib/model_xml/block_parser.rb', line 34 def method_missing *args field *args end |
Instance Attribute Details
#field_set ⇒ Object (readonly)
Returns the value of attribute field_set.
15 16 17 |
# File 'lib/model_xml/block_parser.rb', line 15 def field_set @field_set end |
Class Method Details
.parse(&block) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/model_xml/block_parser.rb', line 6 def parse &block raise "block required" unless block_given? parser = self.new parser.instance_eval &block parser.field_set end |
Instance Method Details
#field(*args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/model_xml/block_parser.rb', line 21 def field *args # if the method is called without arguments, add it as a member of the field set if args.map(&:class) == [Symbol] @field_set << args[0] # otherwise add it as an array else @field_set << args end end |