Class: BCDice::DiceTable::D66LeftRangeTable
- Defined in:
- lib/bcdice/dice_table/d66_left_range_table.rb
Overview
左側(十の位)のみ Range を用いる D66 表
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, sort_type, items) ⇒ D66LeftRangeTable
constructor
A new instance of D66LeftRangeTable.
Methods inherited from D66Table
Constructor Details
#initialize(name, sort_type, items) ⇒ D66LeftRangeTable
Returns a new instance of D66LeftRangeTable.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bcdice/dice_table/d66_left_range_table.rb', line 33 def initialize(name, sort_type, items) = {} items.each do |item| range, right_items = item range.each do |left_value| right_items.each_with_index do |right_item, right_value| key = left_value * 10 + (right_value + 1) [key] = right_item end end end super(name, sort_type, ) end |
Class Method Details
.conv_string_range(x) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bcdice/dice_table/d66_left_range_table.rb', line 18 def conv_string_range(x) if x.include?("..") return Range.new(*x.split("..", 2).map { |n| Integer(n) }) end raise( ArgumentError, "invalid format" ) end |
.from_i18n(key, locale) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/bcdice/dice_table/d66_left_range_table.rb', line 10 def from_i18n(key, locale) table = I18n.t(key, locale: locale) converted_items = table[:items].map do |item| [conv_string_range(item[0]), item[1]] end new(table[:name], table[:d66_sort_type], converted_items) end |