Class: Odca::SchemaParser
- Inherits:
-
Object
- Object
- Odca::SchemaParser
- Defined in:
- lib/odca/schema_parser.rb
Instance Attribute Summary collapse
-
#overlay_dtos ⇒ Object
readonly
Returns the value of attribute overlay_dtos.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #add_attribute(to:, attr_name:, value:) ⇒ Object
- #call ⇒ Object
-
#initialize(records, overlay_dtos) ⇒ SchemaParser
constructor
A new instance of SchemaParser.
Constructor Details
#initialize(records, overlay_dtos) ⇒ SchemaParser
Returns a new instance of SchemaParser.
5 6 7 8 |
# File 'lib/odca/schema_parser.rb', line 5 def initialize(records, ) @records = records @overlay_dtos = end |
Instance Attribute Details
#overlay_dtos ⇒ Object (readonly)
Returns the value of attribute overlay_dtos.
3 4 5 |
# File 'lib/odca/schema_parser.rb', line 3 def @overlay_dtos end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
3 4 5 |
# File 'lib/odca/schema_parser.rb', line 3 def records @records end |
Instance Method Details
#add_attribute(to:, attr_name:, value:) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/odca/schema_parser.rb', line 67 def add_attribute(to:, attr_name:, value:) = to = .class.name.split('::').last begin attribute_class = .class .const_get(.gsub('Overlay', 'Attribute')) validator_class = .class .const_get('InputValidator') rescue => e raise "Not found Attribute Class for '#{}': #{e}" end .add_attribute( attribute_class.new( validator_class.new( attr_name: attr_name, value: value ).call ) ) end |
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/odca/schema_parser.rb', line 10 def call schema_base = Odca::SchemaBase.new( Odca::SchemaBase::Header.new( name: records.first[0], description: records.first[1], classification: records.first[2] ) ) = {} = .map(&:index) records.each do |row| attr_name = row[3] attr_type = row[4] schema_base.add_attribute( SchemaBase::Attribute.new( name: attr_name, type: attr_type, pii: row[5] ) ) .each do |ov_index| next unless row[ov_index] ([ov_index] ||= []) << { name: attr_name, value: row[ov_index] } end end = [] .each do || attrs = [.index] next unless attrs = () attrs.each do |attr| add_attribute( to: , attr_name: attr[:name], value: attr[:value] ) end << Odca::HeadfulOverlay.new( parentful_overlay: Odca::ParentfulOverlay.new( parent: schema_base, overlay: ), role: .role, purpose: .purpose ) end [schema_base, ] end |