Class: Cpr::ClassGenerator

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

Instance Method Summary collapse

Constructor Details

#initialize(prefix, filename) ⇒ ClassGenerator

Returns a new instance of ClassGenerator.



69
70
71
72
# File 'lib/cpr/class_generator.rb', line 69

def initialize(prefix, filename)
  @prefix = prefix
  @filename = filename
end

Instance Method Details

#generateObject



74
75
76
77
78
79
80
81
# File 'lib/cpr/class_generator.rb', line 74

def generate
  rows.each do |row|
    filename = "lib/cpr/#{@prefix}/#{row.name}.rb"
    File.open(filename, 'w') do |file|
      file << row.class_def("Cpr::#{@prefix.capitalize}", row.name)
    end
  end
end

#rowsObject



83
84
85
86
87
88
# File 'lib/cpr/class_generator.rb', line 83

def rows
  doc = Nokogiri::XML.parse(File.read(@filename))
  (doc / "//Table").map do |table|
    RowSpec.parse_from_table(table)
  end
end