Class: Paxmex::Schema::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/paxmex/schema/section.rb

Constant Summary collapse

BLOCK_LENGTH =
450

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/paxmex/schema/section.rb', line 8

def data
  @data
end

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/paxmex/schema/section.rb', line 8

def key
  @key
end

#parent_keyObject (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

Returns:

  • (Boolean)


20
21
22
# File 'lib/paxmex/schema/section.rb', line 20

def abstract?
  !!data['ABSTRACT']
end

#child?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/paxmex/schema/section.rb', line 28

def child?
  !!@parent_key
end

#fieldsObject



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

#lengthObject



59
60
61
# File 'lib/paxmex/schema/section.rb', line 59

def length
  BLOCK_LENGTH
end

#recurring?Boolean

Returns:

  • (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_typesObject



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

Returns:

  • (Boolean)


24
25
26
# File 'lib/paxmex/schema/section.rb', line 24

def trailer?
  !!data['TRAILER']
end

#type_fieldObject



47
48
49
# File 'lib/paxmex/schema/section.rb', line 47

def type_field
  data['TYPE_FIELD']
end

#type_mappingObject



51
52
53
# File 'lib/paxmex/schema/section.rb', line 51

def type_mapping
  data['TYPE_MAPPING']
end

#typesObject



43
44
45
# File 'lib/paxmex/schema/section.rb', line 43

def types
  data['TYPES']
end