Class: Odca::Parser
- Inherits:
-
Object
- Object
- Odca::Parser
- Defined in:
- lib/odca/parser.rb
Defined Under Namespace
Classes: OverlayDto
Instance Attribute Summary collapse
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#overlay_dtos ⇒ Object
readonly
Returns the value of attribute overlay_dtos.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(records, output_dir) ⇒ Parser
constructor
A new instance of Parser.
- #save(schema_base:, overlays:) ⇒ Object
- #save_overlay(headful_overlay, path:) ⇒ Object
- #save_schema_base(schema_base, path:) ⇒ Object
Constructor Details
#initialize(records, output_dir) ⇒ Parser
Returns a new instance of Parser.
11 12 13 14 15 |
# File 'lib/odca/parser.rb', line 11 def initialize(records, output_dir) @overlay_dtos = [] @records = records @output_dir = output_dir end |
Instance Attribute Details
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
9 10 11 |
# File 'lib/odca/parser.rb', line 9 def output_dir @output_dir end |
#overlay_dtos ⇒ Object (readonly)
Returns the value of attribute overlay_dtos.
9 10 11 |
# File 'lib/odca/parser.rb', line 9 def @overlay_dtos end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
9 10 11 |
# File 'lib/odca/parser.rb', line 9 def records @records end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/odca/parser.rb', line 17 def call columns_number = records[0].size (6..columns_number - 1).each do |i| << OverlayDto.new( index: i, name: records[2][i], role: records[0][i], purpose: records[1][i], language: records[3][i] ) end records.slice!(0, 4) schemas = separate_schemas(records) schemas.each do |schema| schema_base, = schema.call next unless schema_base && save(schema_base: schema_base, overlays: ) end end |
#save(schema_base:, overlays:) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/odca/parser.rb', line 54 def save(schema_base:, overlays:) path = "#{output_dir}/#{schema_base.name}" save_schema_base(schema_base, path: path) .each do || next if .empty? (, path: path) end end |
#save_overlay(headful_overlay, path:) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/odca/parser.rb', line 73 def (, path:) = ..class .name.split('::').last hl = HashlinkGenerator.call() File.open("#{path}/#{}-#{hl}.json", 'w') do |f| f.write(JSON.pretty_generate()) end end |
#save_schema_base(schema_base, path:) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/odca/parser.rb', line 65 def save_schema_base(schema_base, path:) FileUtils.mkdir_p(path) unless Dir.exist?(path) File.open("#{path}.json", 'w') do |f| f.write(JSON.pretty_generate(schema_base)) end end |