Class: BCDice::DiceTable::Table
- Inherits:
-
Object
- Object
- BCDice::DiceTable::Table
- Defined in:
- lib/bcdice/dice_table/table.rb
Overview
表を表すクラス
Direct Known Subclasses
GameSystem::BeginningIdol::SkillGetTable, GameSystem::BeginningIdol::TableWithAbnormality, GameSystem::StellarLife::StellarLifeD10Table, GameSystem::Yggdrasill::ChainTable, GameSystem::Yggdrasill::YggTable
Class Method Summary collapse
Instance Method Summary collapse
- #choice(value) ⇒ Object
-
#initialize(name, type, items) ⇒ Table
constructor
A new instance of Table.
-
#roll(bcdice) ⇒ String
表を振る.
Constructor Details
#initialize(name, type, items) ⇒ Table
Returns a new instance of Table.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bcdice/dice_table/table.rb', line 18 def initialize(name, type, items) @name = name @items = items.freeze m = /(\d+)D(\d+)/i.match(type) unless m raise ArgumentError, "Unexpected table type: #{type}" end @times = m[1].to_i @sides = m[2].to_i end |
Class Method Details
.from_i18n(key, locale) ⇒ Table
10 11 12 13 |
# File 'lib/bcdice/dice_table/table.rb', line 10 def self.from_i18n(key, locale) table = I18n.t(key, locale: locale) new(table[:name], table[:type], table[:items]) end |
Instance Method Details
#choice(value) ⇒ Object
39 40 41 42 |
# File 'lib/bcdice/dice_table/table.rb', line 39 def choice(value) index = value - @times return RollResult.new(@name, value, @items[index]) end |
#roll(bcdice) ⇒ String
表を振る
34 35 36 37 |
# File 'lib/bcdice/dice_table/table.rb', line 34 def roll(bcdice) value = bcdice.roll_sum(@times, @sides) return choice(value) end |