Class: RgGen::Core::InputBase::InputData

Inherits:
Object
  • Object
show all
Defined in:
lib/rggen/core/input_base/input_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layer, valid_value_lists, *_args) ⇒ InputData

Returns a new instance of InputData.



7
8
9
10
11
12
13
14
# File 'lib/rggen/core/input_base/input_data.rb', line 7

def initialize(layer, valid_value_lists, *_args)
  @layer = layer
  @valid_value_lists = valid_value_lists
  @values = Hash.new(NAValue)
  @children = []
  define_setter_methods
  block_given? && yield(self)
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



38
39
40
# File 'lib/rggen/core/input_base/input_data.rb', line 38

def children
  @children
end

#layerObject (readonly)

Returns the value of attribute layer.



16
17
18
# File 'lib/rggen/core/input_base/input_data.rb', line 16

def layer
  @layer
end

Instance Method Details

#[](value_name) ⇒ Object



29
30
31
# File 'lib/rggen/core/input_base/input_data.rb', line 29

def [](value_name)
  @values[value_name]
end

#[]=(value_name, position = nil, value) ⇒ Object



25
26
27
# File 'lib/rggen/core/input_base/input_data.rb', line 25

def []=(value_name, position = nil, value)
  value(value_name, value, position)
end

#child(layer, value_list = nil, &block) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/rggen/core/input_base/input_data.rb', line 40

def child(layer, value_list = nil, &block)
  create_child_data(layer) do |child_data|
    child_data.build_by_block(&block)
    child_data.values(value_list)
    @children << child_data
  end
end

#load_file(file) ⇒ Object



48
49
50
# File 'lib/rggen/core/input_base/input_data.rb', line 48

def load_file(file)
  build_by_block { instance_eval(File.binread(file), file, 1) }
end

#value(value_name, value, position = nil) ⇒ Object



18
19
20
21
22
23
# File 'lib/rggen/core/input_base/input_data.rb', line 18

def value(value_name, value, position = nil)
  symbolized_name = value_name.to_sym
  valid_value?(symbolized_name) ||
    raise_unknown_field_error(symbolized_name, position)
  assign_value(symbolized_name, value, position)
end

#values(value_list = nil, position = nil) ⇒ Object



33
34
35
36
# File 'lib/rggen/core/input_base/input_data.rb', line 33

def values(value_list = nil, position = nil)
  value_list && Hash(value_list).each { |n, v| value(n, v, position) }
  @values
end