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.



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

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/paxmex/schema/section.rb', line 6

def data
  @data
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/paxmex/schema/section.rb', line 6

def key
  @key
end

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/paxmex/schema/section.rb', line 18

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

#child?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/paxmex/schema/section.rb', line 26

def child?
  !!@parent_key
end

#fieldsObject



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

#lengthObject



57
58
59
# File 'lib/paxmex/schema/section.rb', line 57

def length
  BLOCK_LENGTH
end

#recurring?Boolean

Returns:

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



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

Returns:

  • (Boolean)


22
23
24
# File 'lib/paxmex/schema/section.rb', line 22

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

#type_fieldObject



45
46
47
# File 'lib/paxmex/schema/section.rb', line 45

def type_field
  data['TYPE_FIELD']
end

#type_mappingObject



49
50
51
# File 'lib/paxmex/schema/section.rb', line 49

def type_mapping
  data['TYPE_MAPPING']
end

#typesObject



41
42
43
# File 'lib/paxmex/schema/section.rb', line 41

def types
  data['TYPES']
end