class UltraMarathon::Store

Public Class Methods

new(new_runners=[]) click to toggle source

Public Instance Methods

# File lib/ultra_marathon/store.rb, line 13
def initialize(new_runners=[])
  new_runners.each do |new_runner|
    add(new_runner)
  end
end

Public Instance Methods

<<(runner) click to toggle source
# File lib/ultra_marathon/store.rb, line 19
def <<(runner)
  store[runner.name] = runner
end
Also aliased as: add
==(other) click to toggle source
# File lib/ultra_marathon/store.rb, line 63
def ==(other)
  if other.is_a? self.class
    other.names == self.names
  else
    false
  end
end
add(runner)
Alias for: <<
each(&block) click to toggle source
# File lib/ultra_marathon/store.rb, line 28
def each(&block)
  runners.each(&block)
end
exist?(name)
Alias for: exists?
exists?(name) click to toggle source
# File lib/ultra_marathon/store.rb, line 58
def exists?(name)
  store.key? name
end
Also aliased as: exist?
failed?(name) click to toggle source
# File lib/ultra_marathon/store.rb, line 52
def failed?(name)
  if exists? name
    !success? name
  end
end
includes_all?(query_names) click to toggle source
# File lib/ultra_marathon/store.rb, line 40
def includes_all?(query_names)
  (Set.new(query_names) - self.names).empty?
end
merge(other_store) click to toggle source
# File lib/ultra_marathon/store.rb, line 24
def merge(other_store)
  self.store.merge!(other_store.store)
end
names() click to toggle source
# File lib/ultra_marathon/store.rb, line 36
def names
  Set.new(store.keys)
end
pluck(&block) click to toggle source
# File lib/ultra_marathon/store.rb, line 32
def pluck(&block)
  runners.map(&block)
end
success?(name) click to toggle source

When determining attributes, the user should always check for existence. If they don't, return nil.

# File lib/ultra_marathon/store.rb, line 46
def success?(name)
  if exists? name
    store[name].success
  end
end

Protected Instance Methods

store() click to toggle source

allow access for another store for merging

# File lib/ultra_marathon/store.rb, line 76
def store
  @store ||= Hash.new
end

Private Instance Methods

runners() click to toggle source

Private Instance Methods

# File lib/ultra_marathon/store.rb, line 84
def runners
  store.values
end