Class: AffirmIt::GroupHug
- Inherits:
-
Object
- Object
- AffirmIt::GroupHug
- Defined in:
- lib/affirmit/grouphug.rb
Overview
A group hug is a collection of affirmations (or other group hugs) that a Facilitator can embrace together.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<<(affirmation) ⇒ Object
- #[](index) ⇒ Object
-
#affirmation_count ⇒ Object
Returns the number of individual affirmations in this group hug, recursively.
- #each ⇒ Object
- #each_affirmation(&block) ⇒ Object
-
#embrace(facilitator) ⇒ Object
Not to be called directly.
-
#frame_of_reference=(frame_of_reference) ⇒ Object
Sets a frame of reference for all the affirmations in this group hug.
-
#initialize(name) ⇒ GroupHug
constructor
A new instance of GroupHug.
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ GroupHug
Returns a new instance of GroupHug.
11 12 13 14 |
# File 'lib/affirmit/grouphug.rb', line 11 def initialize(name) @affirmations = [] @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/affirmit/grouphug.rb', line 9 def name @name end |
Instance Method Details
#<<(affirmation) ⇒ Object
37 38 39 |
# File 'lib/affirmit/grouphug.rb', line 37 def << affirmation @affirmations << affirmation end |
#[](index) ⇒ Object
41 42 43 |
# File 'lib/affirmit/grouphug.rb', line 41 def [] index @affirmations[index] end |
#affirmation_count ⇒ Object
Returns the number of individual affirmations in this group hug, recursively.
66 67 68 69 70 |
# File 'lib/affirmit/grouphug.rb', line 66 def affirmation_count @affirmations.inject(0) do |sum, affirmation| sum + affirmation.affirmation_count end end |
#each ⇒ Object
45 46 47 |
# File 'lib/affirmit/grouphug.rb', line 45 def each @affirmations.each { |affirmation| yield affirmation } end |
#each_affirmation(&block) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/affirmit/grouphug.rb', line 49 def each_affirmation &block @affirmations.each do |affirmation| if affirmation.is_a? GroupHug then affirmation.each_affirmation &block else block.call affirmation end end end |
#embrace(facilitator) ⇒ Object
Not to be called directly. When a facilitator embraces a group hug (or affirmation), the group hug or affirmation embraces the facilitator reciprocally.
29 30 31 32 33 34 35 |
# File 'lib/affirmit/grouphug.rb', line 29 def embrace facilitator facilitator.with_arms_around self do @affirmations.each do |affirmation| affirmation.embrace facilitator end end end |
#frame_of_reference=(frame_of_reference) ⇒ Object
Sets a frame of reference for all the affirmations in this group hug.
19 20 21 22 23 |
# File 'lib/affirmit/grouphug.rb', line 19 def frame_of_reference= frame_of_reference @affirmations.each do |affirmation| affirmation.frame_of_reference = frame_of_reference end end |
#size ⇒ Object
59 60 61 |
# File 'lib/affirmit/grouphug.rb', line 59 def size @affirmations.size end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/affirmit/grouphug.rb', line 72 def to_s "Group hug #{name} with #{affirmation_count} affirmations" end |