class Goalkeeper::Set
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| ...}
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/goalkeeper/set.rb, line 29 def initialize super end
Public Instance Methods
<<(other)
click to toggle source
Calls superclass method
# File lib/goalkeeper/set.rb, line 65 def <<(other) if other.is_a?(Goal) && !include?(other) super else false end end
add(*args)
click to toggle source
Creates a new Goal
. see Goal#initialize for usage
# File lib/goalkeeper/set.rb, line 35 def add(*args) push(Goal.new(*args)) self end
met()
click to toggle source
met returns a Set
with the all the Goals that have been met.
# File lib/goalkeeper/set.rb, line 51 def met subset(select { |g| g.met? }) end
met?()
click to toggle source
met? returns true if all Goals in the set have been met.
# File lib/goalkeeper/set.rb, line 41 def met? unmet.empty? end
met_at()
click to toggle source
nil if this set is not met? otherwise returns the met_at
Time for the last met goal
# File lib/goalkeeper/set.rb, line 57 def met_at if met? self.map(&:met_at).sort.last else nil end end
push(*others)
click to toggle source
# File lib/goalkeeper/set.rb, line 73 def push(*others) others.each do |o| self << o end end
unmet()
click to toggle source
unmet returns a Set
with the all the Goals that have not been met.
# File lib/goalkeeper/set.rb, line 46 def unmet subset(select { |g| !g.met? }) end
Protected Instance Methods
subset(set)
click to toggle source
# File lib/goalkeeper/set.rb, line 81 def subset(set) Goalkeeper::Set.new.tap do |s| set.each {|i| s << i} end end