Class: FifthedSim::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/fifthed_sim/stat.rb

Defined Under Namespace

Classes: DefinitionProxy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Stat

Returns a new instance of Stat.



31
32
33
34
35
# File 'lib/fifthed_sim/stat.rb', line 31

def initialize(hash)
  @value = hash[:value]
  @mod_bonus = (hash[:mod_bonus] || 0)
  @save_mod_bonus = (hash[:save_mod_bonus] || 0)
end

Instance Attribute Details

#mod_bonusObject (readonly)

Returns the value of attribute mod_bonus.



37
38
39
# File 'lib/fifthed_sim/stat.rb', line 37

def mod_bonus
  @mod_bonus
end

#save_mod_bonusObject (readonly)

Returns the value of attribute save_mod_bonus.



37
38
39
# File 'lib/fifthed_sim/stat.rb', line 37

def save_mod_bonus
  @save_mod_bonus
end

#valueObject (readonly)

Returns the value of attribute value.



37
38
39
# File 'lib/fifthed_sim/stat.rb', line 37

def value
  @value
end

Class Method Details

.define(&block) ⇒ Object



21
22
23
24
# File 'lib/fifthed_sim/stat.rb', line 21

def self.define(&block)
  h = DefinitionProxy.new(&block).hash
  self.new(h)
end

.from_value(h) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
# File 'lib/fifthed_sim/stat.rb', line 26

def self.from_value(h)
  raise ArgumentError, "#{h} not fixnum" unless h.is_a?(Fixnum)
  self.new({value: h, save_mod: 0, mod_bonus: 0})
end

Instance Method Details

#modObject



41
42
43
# File 'lib/fifthed_sim/stat.rb', line 41

def mod
  ((@value - 10) / 2) + @mod_bonus
end

#saving_throwObject



45
46
47
# File 'lib/fifthed_sim/stat.rb', line 45

def saving_throw
  1.d(20) + mod + save_mod_bonus
end