class Tablescript::TableEntries

TableEntries

Public Class Methods

new() click to toggle source
# File lib/tablescript/table_entries.rb, line 6
def initialize
  @entries = []
  @next_id = 0
end

Public Instance Methods

add_dynamic(count, &blk) click to toggle source
# File lib/tablescript/table_entries.rb, line 35
def add_dynamic(count, &blk)
  range = next_single_roll..(next_single_roll + count - 1)
  entry = TableEntry.new(next_id, range, blk)
  count.times { @entries << entry }
end
add_fixed(roll, &blk) click to toggle source
# File lib/tablescript/table_entries.rb, line 23
def add_fixed(roll, &blk)
  if roll.nil?
    add_entry(blk)
  elsif roll.is_a?(Integer)
    set_entry(roll, blk)
  elsif roll.is_a?(Range)
    set_range(roll, blk)
  else
    raise Exception, "Unrecognized parameter type (#{roll.class}) for fixed roll definition"
  end
end
entry(index) click to toggle source
# File lib/tablescript/table_entries.rb, line 15
def entry(index)
  @entries[index]
end
lookup(roll) click to toggle source
# File lib/tablescript/table_entries.rb, line 19
def lookup(roll)
  entry(roll - 1)
end
size() click to toggle source
# File lib/tablescript/table_entries.rb, line 11
def size
  @entries.size
end

Private Instance Methods

add_entry(blk) click to toggle source
# File lib/tablescript/table_entries.rb, line 53
def add_entry(blk)
  @entries << TableEntry.new(next_id, next_single_roll, blk)
end
next_id() click to toggle source
# File lib/tablescript/table_entries.rb, line 43
def next_id
  id = @next_id
  @next_id += 1
  id
end
next_single_roll() click to toggle source
# File lib/tablescript/table_entries.rb, line 49
def next_single_roll
  @entries.size + 1
end
set_entry(roll, blk) click to toggle source
# File lib/tablescript/table_entries.rb, line 57
def set_entry(roll, blk)
  @entries[roll - 1] = TableEntry.new(next_id, roll, blk)
end
set_range(range, blk) click to toggle source
# File lib/tablescript/table_entries.rb, line 61
def set_range(range, blk)
  entry = TableEntry.new(next_id, range, blk)
  range.each { |r| @entries[r - 1] = entry }
end