Class: Goalkeeper::List

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/goalkeeper.rb

Overview

List is a collection of Goals to simplify tracking multiple goals.

Create a new list

mylist = Goalkeeper::List.new

Add Goals you want to check for completion

mylist.add("job1").add("job2")
mylist.size
#=> 2

Check if all the goals are completed

mylist.met?
#=> false

Get the unmet Goals

mylist.unmet
#=> [...]

Get the met Goals

mylist.met
#=> [...]

Iterate all Goals

myslist.each {|goal| ...}
myslist.map  {|goal| ...}

Instance Method Summary collapse

Constructor Details

#initializeList

Returns a new instance of List


100
101
102
# File 'lib/goalkeeper.rb', line 100

def initialize
  @list = []
end

Instance Method Details

#add(label, ref: nil) ⇒ Object

Creates a new Goal. see Goal#new for usage


106
107
108
109
# File 'lib/goalkeeper.rb', line 106

def add(label, ref: nil)
  @list.push(Goal.new(label, ref: ref))
  self
end

#metObject


120
121
122
# File 'lib/goalkeeper.rb', line 120

def met
  @list.select {|g| g.met?}
end

#met?Boolean

met? returns true if all Goals in the set have been met.

Returns:

  • (Boolean)

112
113
114
# File 'lib/goalkeeper.rb', line 112

def met?
  unmet.empty?
end

#unmetObject


116
117
118
# File 'lib/goalkeeper.rb', line 116

def unmet
  @list.select {|g| ! g.met?}
end