Class: Score
- Inherits:
-
Object
show all
- Includes:
- CanDisable
- Defined in:
- lib/rubysketch/solitaire/common/score.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from CanDisable
#disable, #disabled, #disabled?, #enable, #enabled, #enabled?
Constructor Details
#initialize(**definitions) ⇒ Score
Returns a new instance of Score.
8
9
10
11
12
|
# File 'lib/rubysketch/solitaire/common/score.rb', line 8
def initialize(**definitions)
super()
@defs, @value = {}, 0
define **definitions
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
14
15
16
|
# File 'lib/rubysketch/solitaire/common/score.rb', line 14
def value
@value
end
|
Instance Method Details
#add(name) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/rubysketch/solitaire/common/score.rb', line 22
def add(name)
return if disabled?
value = @defs[name.intern]
@value += value.to_i if value
@value = 0 if @value < 0
end
|
#define(**definitions) ⇒ Object
16
17
18
19
20
|
# File 'lib/rubysketch/solitaire/common/score.rb', line 16
def define(**definitions)
definitions.each do |name, score|
@defs[name.intern] = score
end
end
|
#load(hash) ⇒ Object
33
34
35
|
# File 'lib/rubysketch/solitaire/common/score.rb', line 33
def load(hash)
@value = hash['score']
end
|
#to_h ⇒ Object
29
30
31
|
# File 'lib/rubysketch/solitaire/common/score.rb', line 29
def to_h()
{score: @value}
end
|