Class: Alki::Execution::TagMap
- Inherits:
-
Object
- Object
- Alki::Execution::TagMap
- Defined in:
- lib/alki/execution/tag_map.rb
Instance Method Summary collapse
- #add(path, tags) ⇒ Object
- #elements_in(tag) ⇒ Object
- #index(key) ⇒ Object
-
#initialize(tag_map = {}) ⇒ TagMap
constructor
A new instance of TagMap.
- #tags ⇒ Object
Constructor Details
#initialize(tag_map = {}) ⇒ TagMap
Returns a new instance of TagMap.
4 5 6 |
# File 'lib/alki/execution/tag_map.rb', line 4 def initialize(tag_map = {}) @tag_map = tag_map end |
Instance Method Details
#add(path, tags) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/alki/execution/tag_map.rb', line 8 def add(path,) .each do |tag,value| @tag_map[tag] ||= {} @tag_map[tag][path] = value end end |
#elements_in(tag) ⇒ Object
15 16 17 |
# File 'lib/alki/execution/tag_map.rb', line 15 def elements_in(tag) (@tag_map[tag] && @tag_map[tag].keys) || [] end |
#index(key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/alki/execution/tag_map.rb', line 19 def index(key) new_tag_map = {} @tag_map.each do |tag,tagged| tagged.each do |path,value| if path.empty? || path[0] == key.to_sym new_tag_map[tag] ||= {} new_path = path[1..-1] || [] new_tag_map[tag][new_path] = value end end end self.class.new new_tag_map end |
#tags ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/alki/execution/tag_map.rb', line 33 def Hash.new.tap do || @tag_map.each do |tag,tagged| [tag] = tagged[[]] end end end |