Class: Obo::Stanza
- Inherits:
-
Object
- Object
- Obo::Stanza
- Defined in:
- lib/obo/stanza.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tagvalues ⇒ Object
readonly
Returns the value of attribute tagvalues.
Instance Method Summary collapse
- #[](tag) ⇒ Object
- #add(tag, value) ⇒ Object
-
#initialize(name) ⇒ Stanza
constructor
A new instance of Stanza.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(name) ⇒ Stanza
Returns a new instance of Stanza.
6 7 8 9 |
# File 'lib/obo/stanza.rb', line 6 def initialize(name) @name = name @tagvalues = Hash.new{|h,k| h[k] = []} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/obo/stanza.rb', line 32 def method_missing(method, *args, &block) values = self[method.to_s] if values return values elsif method =~ /\?$/ self.send(method[0..-2]) else raise NoMethodError, "No method #{method} on #{self.class}" end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/obo/stanza.rb', line 3 def name @name end |
#tagvalues ⇒ Object (readonly)
Returns the value of attribute tagvalues.
4 5 6 |
# File 'lib/obo/stanza.rb', line 4 def tagvalues @tagvalues end |
Instance Method Details
#[](tag) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/obo/stanza.rb', line 11 def [](tag) values = @tagvalues[tag] case values.length when 0 nil when 1 values.first else values end end |
#add(tag, value) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/obo/stanza.rb', line 22 def add(tag,value) @tagvalues[tag] << case value when 'true' true when 'false' false else value end end |