Class: Tablescript::TableEntries
- Inherits:
-
Object
- Object
- Tablescript::TableEntries
- Defined in:
- lib/tablescript/table_entries.rb
Overview
TableEntries
Instance Method Summary collapse
- #add_dynamic(count, &blk) ⇒ Object
- #add_fixed(roll, &blk) ⇒ Object
- #entry(index) ⇒ Object
-
#initialize ⇒ TableEntries
constructor
A new instance of TableEntries.
- #lookup(roll) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ TableEntries
Returns a new instance of TableEntries.
6 7 8 9 |
# File 'lib/tablescript/table_entries.rb', line 6 def initialize @entries = [] @next_id = 0 end |
Instance Method Details
#add_dynamic(count, &blk) ⇒ Object
35 36 37 38 39 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
15 16 17 |
# File 'lib/tablescript/table_entries.rb', line 15 def entry(index) @entries[index] end |
#lookup(roll) ⇒ Object
19 20 21 |
# File 'lib/tablescript/table_entries.rb', line 19 def lookup(roll) entry(roll - 1) end |
#size ⇒ Object
11 12 13 |
# File 'lib/tablescript/table_entries.rb', line 11 def size @entries.size end |