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.
10 11 12 13 14 |
# File 'lib/paxmex/schema/section.rb', line 10 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.
8 9 10 |
# File 'lib/paxmex/schema/section.rb', line 8 def data @data end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/paxmex/schema/section.rb', line 8 def key @key end |
#parent_key ⇒ Object (readonly)
Returns the value of attribute parent_key.
8 9 10 |
# File 'lib/paxmex/schema/section.rb', line 8 def parent_key @parent_key end |
Instance Method Details
#abstract? ⇒ Boolean
20 21 22 |
# File 'lib/paxmex/schema/section.rb', line 20 def abstract? !!data['ABSTRACT'] end |
#child? ⇒ Boolean
28 29 30 |
# File 'lib/paxmex/schema/section.rb', line 28 def child? !!@parent_key end |
#fields ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/paxmex/schema/section.rb', line 32 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
59 60 61 |
# File 'lib/paxmex/schema/section.rb', line 59 def length BLOCK_LENGTH end |
#recurring? ⇒ Boolean
16 17 18 |
# File 'lib/paxmex/schema/section.rb', line 16 def recurring? !!data['RECURRING'] end |
#section_for_type(type) ⇒ Object
55 56 57 |
# File 'lib/paxmex/schema/section.rb', line 55 def section_for_type(type) sections_for_types.detect { |t| t.key == type_mapping[type] } end |
#sections_for_types ⇒ Object
63 64 65 |
# File 'lib/paxmex/schema/section.rb', line 63 def sections_for_types @sections_for_types ||= types.map { |k, v| self.class.new(k, v) } end |
#trailer? ⇒ Boolean
24 25 26 |
# File 'lib/paxmex/schema/section.rb', line 24 def trailer? !!data['TRAILER'] end |
#type_field ⇒ Object
47 48 49 |
# File 'lib/paxmex/schema/section.rb', line 47 def type_field data['TYPE_FIELD'] end |
#type_mapping ⇒ Object
51 52 53 |
# File 'lib/paxmex/schema/section.rb', line 51 def type_mapping data['TYPE_MAPPING'] end |
#types ⇒ Object
43 44 45 |
# File 'lib/paxmex/schema/section.rb', line 43 def types data['TYPES'] end |