Class: Tablescript::Table
- Inherits:
-
Object
- Object
- Tablescript::Table
- Defined in:
- lib/tablescript/table.rb
Overview
Table
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #d(count = 1, &blk) ⇒ Object
- #dice_to_roll ⇒ Object
- #f(roll = nil, &blk) ⇒ Object
-
#initialize(name, namespace, &blk) ⇒ Table
constructor
A new instance of Table.
- #lookup(roll) ⇒ Object
- #lookup_on(path, roll) ⇒ Object
- #roll_on(path) ⇒ Object
- #roll_on_and_ignore(path, *args) ⇒ Object
- #roll_on_and_ignore_duplicates(path, times) ⇒ Object
Constructor Details
#initialize(name, namespace, &blk) ⇒ Table
Returns a new instance of Table.
25 26 27 28 29 30 |
# File 'lib/tablescript/table.rb', line 25 def initialize(name, namespace, &blk) @name = name @namespace = namespace @entries = TableEntries.new instance_eval(&blk) end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
23 24 25 |
# File 'lib/tablescript/table.rb', line 23 def entries @entries end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/tablescript/table.rb', line 23 def name @name end |
Instance Method Details
#d(count = 1, &blk) ⇒ Object
36 37 38 |
# File 'lib/tablescript/table.rb', line 36 def d(count = 1, &blk) @entries.add_dynamic(count, &blk) end |
#dice_to_roll ⇒ Object
48 49 50 |
# File 'lib/tablescript/table.rb', line 48 def dice_to_roll "d#{@entries.size}" end |
#f(roll = nil, &blk) ⇒ Object
32 33 34 |
# File 'lib/tablescript/table.rb', line 32 def f(roll = nil, &blk) @entries.add_fixed(roll, &blk) end |
#lookup(roll) ⇒ Object
40 41 42 |
# File 'lib/tablescript/table.rb', line 40 def lookup(roll) @entries.lookup(roll).evaluate(roll, self) end |
#lookup_on(path, roll) ⇒ Object
44 45 46 |
# File 'lib/tablescript/table.rb', line 44 def lookup_on(path, roll) LookupStrategy.new(resolve(path.to_s), roll).value end |
#roll_on(path) ⇒ Object
52 53 54 |
# File 'lib/tablescript/table.rb', line 52 def roll_on(path) RollStrategy.new(resolve(path.to_s)).value end |
#roll_on_and_ignore(path, *args) ⇒ Object
56 57 58 |
# File 'lib/tablescript/table.rb', line 56 def roll_on_and_ignore(path, *args) RollAndIgnoreStrategy.new(resolve(path.to_s), RpgLib::RollSet.new(*args)).value end |
#roll_on_and_ignore_duplicates(path, times) ⇒ Object
60 61 62 |
# File 'lib/tablescript/table.rb', line 60 def roll_on_and_ignore_duplicates(path, times) RollAndIgnoreDuplicatesStrategy.new(resolve(path.to_s), times).value end |