Class: Groupy::Group
- Inherits:
-
Object
- Object
- Groupy::Group
- Defined in:
- lib/groupy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sub_groups ⇒ Object
readonly
Returns the value of attribute sub_groups.
Instance Method Summary collapse
-
#initialize(name, &block) ⇒ Group
constructor
A new instance of Group.
- #subgroups ⇒ Object
- #value_groups ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Group
Returns a new instance of Group.
26 27 28 29 30 31 |
# File 'lib/groupy.rb', line 26 def initialize(name, &block) @name = name @sub_groups = [] instance_eval(&block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/groupy.rb', line 32 def name @name end |
#sub_groups ⇒ Object (readonly)
Returns the value of attribute sub_groups.
32 33 34 |
# File 'lib/groupy.rb', line 32 def sub_groups @sub_groups end |
Instance Method Details
#subgroups ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/groupy.rb', line 48 def subgroups self.sub_groups.inject({}) do |hash, g| if g.respond_to?(:subgroups) hash.merge!(g.subgroups) end hash[g.name] = g.values hash end end |
#value_groups ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/groupy.rb', line 38 def value_groups self.sub_groups.inject([]) do |array, sg| if sg.is_a?(Value) array << sg else array += sg.value_groups end end end |
#values ⇒ Object
34 35 36 |
# File 'lib/groupy.rb', line 34 def values value_groups.map{|g| g.value} end |