Class: Cpr::RowSpec

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/cpr/class_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_from_table(table) ⇒ Object



39
40
41
42
43
# File 'lib/cpr/class_generator.rb', line 39

def self.parse_from_table(table)
  RowSpec.new(:name => table["name"],
    :title => table["title"],
    :fields => table.xpath("TR[position() != 1]").map {|tr| FieldSpec.parse_from_tr(tr)}.compact)
end

Instance Method Details

#class_def(module_name, class_name) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cpr/class_generator.rb', line 45

def class_def(module_name, class_name)
  <<DEF
# coding: utf-8
module #{module_name}
class #{class_name} < Cpr::Row
\ttitle '#{title}'

#{field_defs}
end
end
DEF
end

#field_defsObject



58
59
60
# File 'lib/cpr/class_generator.rb', line 58

def field_defs
  fields.map {|field| "\t#{field.field_def}" }*"\n"
end

#to_sObject



62
63
64
65
# File 'lib/cpr/class_generator.rb', line 62

def to_s
  "#{title} - #{name}\n" +
    fields.map {|field| "\t#{field}" }*"\n"
end