class Tablescript::Table
Attributes
entries[R]
name[R]
Public Class Methods
new(name, namespace, &blk)
click to toggle source
# File lib/tablescript/table.rb, line 25 def initialize(name, namespace, &blk) @name = name @namespace = namespace @entries = TableEntries.new instance_eval(&blk) end
Public Instance Methods
d(count = 1, &blk)
click to toggle source
# File lib/tablescript/table.rb, line 36 def d(count = 1, &blk) @entries.add_dynamic(count, &blk) end
dice_to_roll()
click to toggle source
# File lib/tablescript/table.rb, line 48 def dice_to_roll "d#{@entries.size}" end
f(roll = nil, &blk)
click to toggle source
# File lib/tablescript/table.rb, line 32 def f(roll = nil, &blk) @entries.add_fixed(roll, &blk) end
lookup(roll)
click to toggle source
# File lib/tablescript/table.rb, line 40 def lookup(roll) @entries.lookup(roll).evaluate(roll, self) end
lookup_on(path, roll)
click to toggle source
# File lib/tablescript/table.rb, line 44 def lookup_on(path, roll) LookupStrategy.new(resolve(path.to_s), roll).value end
roll_on(path)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/tablescript/table.rb, line 60 def roll_on_and_ignore_duplicates(path, times) RollAndIgnoreDuplicatesStrategy.new(resolve(path.to_s), times).value end
Private Instance Methods
resolve(path)
click to toggle source
# File lib/tablescript/table.rb, line 66 def resolve(path) namespace = @namespace until namespace.nil? return namespace.resolve(path) if namespace.resolve?(path) namespace = namespace.parent end raise Exception, "No such table #{path}" end