Class: Wombat::PropertyContainer
- Inherits:
-
Hash
- Object
- Hash
- Wombat::PropertyContainer
show all
- Defined in:
- lib/wombat/property_container.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
7
8
9
|
# File 'lib/wombat/property_container.rb', line 7
def initialize
@iterators = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/wombat/property_container.rb', line 11
def method_missing method, *args, &block
if args.empty? && block
self["#{method.to_s}"] = PropertyContainer.new unless self["#{method.to_s}"]
block.call(self["#{method.to_s}"])
else
self[method.to_s] = Property.new(
name: method.to_s,
selector: args.first,
format: args[1],
namespaces: args[2],
callback: block)
end
end
|
Instance Attribute Details
#iterators ⇒ Object
Returns the value of attribute iterators.
5
6
7
|
# File 'lib/wombat/property_container.rb', line 5
def iterators
@iterators
end
|
Instance Method Details
#all_properties ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/wombat/property_container.rb', line 28
def all_properties
values.flat_map { |v|
if v.kind_of? PropertyContainer
v.all_properties
elsif v.kind_of? Property
v
else
nil
end
}.compact
end
|
#flatten ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/wombat/property_container.rb', line 40
def flatten
Hash.new.tap do |h|
keys.map do |k|
if self[k].kind_of?(PropertyContainer) || self[k].kind_of?(Property)
h[k] = self[k].flatten
end
end
end.merge(iterators.inject({}) {|memo, i| memo.merge(i.flatten) })
end
|
#for_each(selector) ⇒ Object
50
51
52
53
54
|
# File 'lib/wombat/property_container.rb', line 50
def for_each selector
Iterator.new(selector).tap do |i|
iterators << i
end
end
|
#to_ary ⇒ Object
25
26
|
# File 'lib/wombat/property_container.rb', line 25
def to_ary
end
|