Class: Rootage::ScenarioDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/rootage/scenario.rb

Overview

ScenarioDefinition is an information table for Scenario class.

Instance Method Summary collapse

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.

Parameters:

  • key (Object)

    the key

Returns:

  • (Object)

    the block



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

#cloneObject



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.

Parameters:

  • key (Symbol)

    key name

  • val (Object) (defaults to: nil)

    item's value

  • args_block (Proc)

    value's arguments



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

#descObject



62
63
64
# File 'lib/rootage/scenario.rb', line 62

def desc
  self[:desc]
end

#scenario_nameObject



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.

Parameters:

  • key (Object)

    the key

Returns:

  • (Object)

    the value



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