Class: Obo::Stanza

Inherits:
Object
  • Object
show all
Defined in:
lib/obo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Stanza

Returns a new instance of Stanza.



26
27
28
29
# File 'lib/obo.rb', line 26

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



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/obo.rb', line 52

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

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/obo.rb', line 23

def name
  @name
end

#tagvaluesObject (readonly)

Returns the value of attribute tagvalues.



24
25
26
# File 'lib/obo.rb', line 24

def tagvalues
  @tagvalues
end

Instance Method Details

#[](tag) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/obo.rb', line 31

def [](tag)
  values = @tagvalues[tag]
  case values.length
  when 0
    nil
  when 1
    values.first
  else values
  end
end

#add(tag, value) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/obo.rb', line 42

def add(tag,value)
  @tagvalues[tag] << case value
                     when 'true'
                       true
                     when 'false'
                       false
                     else value  
                     end
end