Class: GO::TagSet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTagSet

Returns a new instance of TagSet.



6
7
8
# File 'lib/go.rb', line 6

def initialize
  @tags = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/go.rb', line 26

def method_missing sym
  set = @tags[sym]
  if set 
    if set.size == 1
      set.first
    else
      set
    end
  else
    super
  end
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



10
11
12
# File 'lib/go.rb', line 10

def tags
  @tags
end

Instance Method Details

#add_tag(line) ⇒ Object



11
12
13
14
15
16
# File 'lib/go.rb', line 11

def add_tag line
  tag, value = line.scan(/^(.*?): (.*?)(?: !.*)?$/).flatten
  tag = tag.to_sym
  @tags[tag] ||= Set.new
  @tags[tag] << value
end

#respond_to_missing?(sym, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/go.rb', line 18

def respond_to_missing? sym, include_all = false
  @tags.has_key?(sym) || super
end

#tag(sym) ⇒ Object



22
23
24
# File 'lib/go.rb', line 22

def tag sym
  @tags[sym] || []
end