Class: Paxmex::Schema::Section
- Inherits:
-
Object
- Object
- Paxmex::Schema::Section
- Defined in:
- lib/paxmex/schema/section.rb
Constant Summary collapse
- BLOCK_LENGTH =
450
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#parent_key ⇒ Object
readonly
Returns the value of attribute parent_key.
Instance Method Summary collapse
- #abstract? ⇒ Boolean
- #child? ⇒ Boolean
- #fields ⇒ Object
-
#initialize(key, data) ⇒ Section
constructor
A new instance of Section.
- #length ⇒ Object
- #recurring? ⇒ Boolean
- #section_for_type(type) ⇒ Object
- #sections_for_types ⇒ Object
- #trailer? ⇒ Boolean
- #type_field ⇒ Object
- #type_mapping ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(key, data) ⇒ Section
Returns a new instance of Section.
8 9 10 11 12 |
# File 'lib/paxmex/schema/section.rb', line 8 def initialize(key, data) @parent_key = data.delete('PARENT') { nil } @key = key @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/paxmex/schema/section.rb', line 6 def data @data end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/paxmex/schema/section.rb', line 6 def key @key end |
#parent_key ⇒ Object (readonly)
Returns the value of attribute parent_key.
6 7 8 |
# File 'lib/paxmex/schema/section.rb', line 6 def parent_key @parent_key end |
Instance Method Details
#abstract? ⇒ Boolean
18 19 20 |
# File 'lib/paxmex/schema/section.rb', line 18 def abstract? !!data['ABSTRACT'] end |
#child? ⇒ Boolean
26 27 28 |
# File 'lib/paxmex/schema/section.rb', line 26 def child? !!@parent_key end |
#fields ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/paxmex/schema/section.rb', line 30 def fields @fields ||= data['FIELDS'].map do |field| Paxmex::Schema::Field.new( name: field['NAME'], start: field['RANGE'].first, final: field['RANGE'].last, type: field['TYPE'] ) end end |
#length ⇒ Object
57 58 59 |
# File 'lib/paxmex/schema/section.rb', line 57 def length BLOCK_LENGTH end |
#recurring? ⇒ Boolean
14 15 16 |
# File 'lib/paxmex/schema/section.rb', line 14 def recurring? !!data['RECURRING'] end |
#section_for_type(type) ⇒ Object
53 54 55 |
# File 'lib/paxmex/schema/section.rb', line 53 def section_for_type(type) sections_for_types.detect { |t| t.key == type_mapping[type] } end |
#sections_for_types ⇒ Object
61 62 63 |
# File 'lib/paxmex/schema/section.rb', line 61 def sections_for_types @sections_for_types ||= types.map { |k, v| self.class.new(k, v) } end |
#trailer? ⇒ Boolean
22 23 24 |
# File 'lib/paxmex/schema/section.rb', line 22 def trailer? !!data['TRAILER'] end |
#type_field ⇒ Object
45 46 47 |
# File 'lib/paxmex/schema/section.rb', line 45 def type_field data['TYPE_FIELD'] end |
#type_mapping ⇒ Object
49 50 51 |
# File 'lib/paxmex/schema/section.rb', line 49 def type_mapping data['TYPE_MAPPING'] end |
#types ⇒ Object
41 42 43 |
# File 'lib/paxmex/schema/section.rb', line 41 def types data['TYPES'] end |