Class: UltraMarathon::Store

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/ultra_marathon/store.rb

Instance Method Summary collapse

Constructor Details

#initialize(new_runners = []) ⇒ Store

Public Instance Methods



13
14
15
16
17
# File 'lib/ultra_marathon/store.rb', line 13

def initialize(new_runners=[])
  new_runners.each do |new_runner|
    add(new_runner)
  end
end

Instance Method Details

#<<(runner) ⇒ Object Also known as: add



19
20
21
# File 'lib/ultra_marathon/store.rb', line 19

def <<(runner)
  store[runner.name] = runner
end

#==(other) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/ultra_marathon/store.rb', line 59

def ==(other)
  if other.is_a? self.class
    other.names == self.names
  else
    false
  end
end

#each(&block) ⇒ Object



24
25
26
# File 'lib/ultra_marathon/store.rb', line 24

def each(&block)
  runners.each(&block)
end

#exists?(name) ⇒ Boolean Also known as: exist?

Returns:

  • (Boolean)


54
55
56
# File 'lib/ultra_marathon/store.rb', line 54

def exists?(name)
  store.key? name
end

#failed?(name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/ultra_marathon/store.rb', line 48

def failed?(name)
  if exists? name
    !success? name
  end
end

#includes_all?(query_names) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ultra_marathon/store.rb', line 36

def includes_all?(query_names)
  (Set.new(query_names) - self.names).empty?
end

#namesObject



32
33
34
# File 'lib/ultra_marathon/store.rb', line 32

def names
  Set.new(store.keys)
end

#pluck(&block) ⇒ Object



28
29
30
# File 'lib/ultra_marathon/store.rb', line 28

def pluck(&block)
  runners.map(&block)
end

#success?(name) ⇒ Boolean

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

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/ultra_marathon/store.rb', line 42

def success?(name)
  if exists? name
    store[name].success
  end
end