Class: Characterizable::Snapshot

Inherits:
BetterHash
  • Object
show all
Defined in:
lib/characterizable/snapshot.rb

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

#universeObject (readonly)

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_snapshotObject



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

#effectiveObject



35
36
37
# File 'lib/characterizable/snapshot.rb', line 35

def effective
  universe.characterizable_base.characteristics.select { |_, c| c.effective?(self) }
end

#lackingObject



44
45
46
# File 'lib/characterizable/snapshot.rb', line 44

def lacking
  universe.characterizable_base.characteristics.slice(*(lacking_keys - wasted_keys))
end

#lacking_keysObject



32
33
34
# File 'lib/characterizable/snapshot.rb', line 32

def lacking_keys
  @lacking_keys ||= Array.new
end

#potentialObject



38
39
40
# File 'lib/characterizable/snapshot.rb', line 38

def potential
  universe.characterizable_base.characteristics.select { |_, c| c.potential?(self) }
end

#trumpedObject



47
48
49
# File 'lib/characterizable/snapshot.rb', line 47

def trumped
  universe.characterizable_base.characteristics.slice(*trumped_keys)
end

#trumped_keysObject



29
30
31
# File 'lib/characterizable/snapshot.rb', line 29

def trumped_keys
  @trumped_keys ||= Array.new
end

#wastedObject



41
42
43
# File 'lib/characterizable/snapshot.rb', line 41

def wasted
  universe.characterizable_base.characteristics.slice(*wasted_keys)
end

#wasted_keysObject



26
27
28
# File 'lib/characterizable/snapshot.rb', line 26

def wasted_keys
  @wasted_keys ||= Array.new
end