Class: Goalkeeper::Set
- Inherits:
-
Array
- Object
- Array
- Goalkeeper::Set
- Defined in:
- lib/goalkeeper/set.rb
Overview
Set is an Array of Goals to simplify tracking multiple goals. Since Set is an array, you have all Array methods available.
Create a new set
myset = Goalkeeper::Set.new
Add Goals you want to check for completion
myset.add("job1").add("job2")
myset.size
#=> 2
Check if all the goals are completed
myset.met?
#=> false
Get the unmet Goals
myset.unmet
#=> [...]
Get the met Goals
myset.met
#=> [...]
Iterate all Goals
myset.each {|goal| ...}
myset.map {|goal| ...}
Instance Method Summary collapse
- #<<(other) ⇒ Object
-
#add(*args) ⇒ Object
Creates a new Goal.
-
#initialize ⇒ Set
constructor
A new instance of Set.
-
#met ⇒ Object
met returns a Set with the all the Goals that have been met.
-
#met? ⇒ Boolean
met? returns true if all Goals in the set have been met.
-
#met_at ⇒ Object
nil if this set is not met? otherwise returns the met_at Time for the last met goal.
- #push(*others) ⇒ Object
-
#unmet ⇒ Object
unmet returns a Set with the all the Goals that have not been met.
Constructor Details
#initialize ⇒ Set
Returns a new instance of Set.
29 30 31 |
# File 'lib/goalkeeper/set.rb', line 29 def initialize super end |
Instance Method Details
#<<(other) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/goalkeeper/set.rb', line 65 def <<(other) if other.is_a?(Goal) && !include?(other) super else false end end |
#add(*args) ⇒ Object
Creates a new Goal. see Goal#initialize for usage
35 36 37 38 |
# File 'lib/goalkeeper/set.rb', line 35 def add(*args) push(Goal.new(*args)) self end |
#met ⇒ Object
met returns a Set with the all the Goals that have been met.
51 52 53 |
# File 'lib/goalkeeper/set.rb', line 51 def met subset(select { |g| g.met? }) end |
#met? ⇒ Boolean
met? returns true if all Goals in the set have been met.
41 42 43 |
# File 'lib/goalkeeper/set.rb', line 41 def met? unmet.empty? end |
#met_at ⇒ Object
nil if this set is not met? otherwise returns the met_at Time for the last met goal
57 58 59 60 61 62 63 |
# File 'lib/goalkeeper/set.rb', line 57 def met_at if met? self.map(&:met_at).sort.last else nil end end |
#push(*others) ⇒ Object
73 74 75 76 77 |
# File 'lib/goalkeeper/set.rb', line 73 def push(*others) others.each do |o| self << o end end |
#unmet ⇒ Object
unmet returns a Set with the all the Goals that have not been met.
46 47 48 |
# File 'lib/goalkeeper/set.rb', line 46 def unmet subset(select { |g| !g.met? }) end |