Class: Characterizable::Snapshot
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from BetterHash
#as_json, #reject, #select, #slice, #to_hash
Constructor Details
#initialize(universe) ⇒ Snapshot
Returns a new instance of Snapshot.
4
5
6
7
|
# File 'lib/characterizable/snapshot.rb', line 4
def initialize(universe)
@universe = universe
_take_snapshot
end
|
Instance Attribute Details
#universe ⇒ Object
Returns the value of attribute universe.
3
4
5
|
# File 'lib/characterizable/snapshot.rb', line 3
def universe
@universe
end
|
Instance Method Details
#[]=(key, value) ⇒ Object
22
23
24
25
|
# File 'lib/characterizable/snapshot.rb', line 22
def []=(key, value)
universe.expire_snapshot!
super
end
|
#_take_snapshot ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/characterizable/snapshot.rb', line 8
def _take_snapshot
universe.characterizable_base.characteristics.each do |_, c|
if c.known?(universe)
if c.effective?(universe)
self[c.name] = c.value(universe)
elsif c.trumped?(universe)
trumped_keys.push c.name
elsif !c.revealed?(universe)
wasted_keys.push c.name
lacking_keys.push c.prerequisite
end
end
end
end
|
#effective ⇒ Object
35
36
37
|
# File 'lib/characterizable/snapshot.rb', line 35
def effective
universe.characterizable_base.characteristics.select { |_, c| c.effective?(self) }
end
|
#lacking ⇒ Object
44
45
46
|
# File 'lib/characterizable/snapshot.rb', line 44
def lacking
universe.characterizable_base.characteristics.slice(*(lacking_keys - wasted_keys))
end
|
#lacking_keys ⇒ Object
32
33
34
|
# File 'lib/characterizable/snapshot.rb', line 32
def lacking_keys
@lacking_keys ||= Array.new
end
|
#potential ⇒ Object
38
39
40
|
# File 'lib/characterizable/snapshot.rb', line 38
def potential
universe.characterizable_base.characteristics.select { |_, c| c.potential?(self) }
end
|
#trumped ⇒ Object
47
48
49
|
# File 'lib/characterizable/snapshot.rb', line 47
def trumped
universe.characterizable_base.characteristics.slice(*trumped_keys)
end
|
#trumped_keys ⇒ Object
29
30
31
|
# File 'lib/characterizable/snapshot.rb', line 29
def trumped_keys
@trumped_keys ||= Array.new
end
|
#wasted ⇒ Object
41
42
43
|
# File 'lib/characterizable/snapshot.rb', line 41
def wasted
universe.characterizable_base.characteristics.slice(*wasted_keys)
end
|
#wasted_keys ⇒ Object
26
27
28
|
# File 'lib/characterizable/snapshot.rb', line 26
def wasted_keys
@wasted_keys ||= Array.new
end
|