Class: Kwatable::Manipulator

Inherits:
Object
  • Object
show all
Includes:
Assertion
Defined in:
lib/kwatable/manipulator.rb

Overview

ex.

tabledef = YAML.load_file('tabledef.yaml')
manipulator = Kwatable::Manipulator.new
tabledef = manipulator.manipulate(tabledef)
p tabledef[:columns]
p tabledef[:tables]

Instance Method Summary collapse

Methods included from Assertion

assert, assert!, unreachable

Constructor Details

#initialize(options = {}) ⇒ Manipulator

Returns a new instance of Manipulator.



27
28
29
# File 'lib/kwatable/manipulator.rb', line 27

def initialize(options={})
  @overridable = options[:overridable]
end

Instance Method Details

#manipulate(tabledef) ⇒ Object

def parse(input)

str = ''
input.each_line do |line|
   str << line.gsub(/([^\t]{8})|([^\t]*)\t/n){[$+].pack("A8")}    ## expand tab
end
tabledef = YAML.load(str)
manipulate(tabledef)
return tabledef

end



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/kwatable/manipulator.rb', line 41

def manipulate(tabledef)
  #assert unless tabledef.is_a?(Hash)
  return tabledef unless tabledef.is_a?(Hash)

  column_map, patterned_columns = _manipulate_columns(tabledef['columns'])
  #assert unless column_map.is_a?(Hash)
  #assert unless patterned_columns.is_a?(Array)

  table_map = _manipulate_tables(tabledef['tables'], column_map, patterned_columns)
  #assert unless table_map.is_a?(Hash)

  tabledef['column_map'] = column_map         # Hash
  tabledef['table_map'] = table_map           # Hash
  return tabledef
end