Class: Rootage::ScenarioDefinition
- Inherits:
-
Object
- Object
- Rootage::ScenarioDefinition
- Defined in:
- lib/rootage/scenario.rb
Overview
ScenarioDefinition is an information table for Scenario class.
Instance Method Summary collapse
- #[]=(key, val) ⇒ Object
-
#block_of(key) ⇒ Object
Return the item block of the key.
- #clone ⇒ Object
-
#define(key, val = nil, &block) ⇒ void
Define a scenario information that associates key and value.
- #desc ⇒ Object
-
#initialize(table = Hash.new) ⇒ ScenarioDefinition
constructor
Create a new information table.
- #scenario_name ⇒ Object
-
#value_of(key) ⇒ Object
(also: #[])
Return the item value of the key.
Constructor Details
#initialize(table = Hash.new) ⇒ ScenarioDefinition
Create a new information table.
5 6 7 8 |
# File 'lib/rootage/scenario.rb', line 5 def initialize(table=Hash.new) @table = table self[:name] ||= "anonymous" end |
Instance Method Details
#[]=(key, val) ⇒ Object
54 55 56 |
# File 'lib/rootage/scenario.rb', line 54 def []=(key, val) define(key, val) end |
#block_of(key) ⇒ Object
Return the item block of the key.
48 49 50 51 52 |
# File 'lib/rootage/scenario.rb', line 48 def block_of(key) if @table.has_key?(key) @table[key][:block] end end |
#clone ⇒ Object
66 67 68 |
# File 'lib/rootage/scenario.rb', line 66 def clone self.class.new(@table.clone) end |
#define(key, val = nil, &block) ⇒ void
This method returns an undefined value.
Define a scenario information that associates key and value.
22 23 24 25 26 27 |
# File 'lib/rootage/scenario.rb', line 22 def define(key, val=nil, &block) if val.nil? and not(block_given?) raise ArgumentError.new("Cannot define %{key} with no data." % {key: key}) end @table[key] = {value: val, block: block} end |
#desc ⇒ Object
62 63 64 |
# File 'lib/rootage/scenario.rb', line 62 def desc self[:desc] end |
#scenario_name ⇒ Object
58 59 60 |
# File 'lib/rootage/scenario.rb', line 58 def scenario_name self[:name] end |
#value_of(key) ⇒ Object Also known as: []
Return the item value of the key.
35 36 37 38 39 |
# File 'lib/rootage/scenario.rb', line 35 def value_of(key) if @table.has_key?(key) @table[key][:value] end end |