Class: Rober::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/rober/reader.rb

Class Method Summary collapse

Class Method Details

.file_read(path) ⇒ Object



30
31
32
33
# File 'lib/rober/reader.rb', line 30

def self.file_read(path)
  res = File.read(path)
  res.gsub(/\r\n/, "
")
end

.read(path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rober/reader.rb', line 5

def self.read(path)
  doc = Nokogiri::XML(file_read(path))
  entities = []
  doc.xpath('/ERD/ENTITY').each do |it|
    entity = Rober::Entity.new
    entity.logical_name = it[:"L-NAME"]
    entity.physical_name = it[:"P-NAME"]
    entity.comment = it[:"COMMENT"]
    it.xpath('ATTR').each do |attr|
      attribute = Rober::Attribute.new
      attribute.logical_name = attr[:"L-NAME"]
      attribute.physical_name = attr[:"P-NAME"]
      attribute.datatype = attr[:"DATATYPE"]
      attribute.length = attr[:"LENGTH"]
      attribute.scale = attr[:"SCALE"]
      attribute.null = attr[:"NULL"]
      attribute.def = attr[:"DEF"]
      attribute.pk = attr[:"PK"]
      entity.add(attribute)
    end
    entities << entity
  end
  {entities: entities}
end