Class: Atco::Header
- Inherits:
-
Object
- Object
- Atco::Header
- Defined in:
- lib/atco/header.rb
Overview
Atco::Header is a class to abstract ATCO-CIF Header data.
Instance Attribute Summary collapse
-
#file_originator ⇒ Object
Returns the value of attribute file_originator.
-
#file_type ⇒ Object
Returns the value of attribute file_type.
-
#production_datetime ⇒ Object
Returns the value of attribute production_datetime.
-
#source_product ⇒ Object
Returns the value of attribute source_product.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.parse(line) ⇒ Object
Public: Parse a header line from an ATCO-CIF file.
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(data) ⇒ Header
constructor
A new instance of Header.
- #to_json(*attrs) ⇒ Object
Constructor Details
#initialize(data) ⇒ Header
Returns a new instance of Header.
26 27 28 29 30 31 32 |
# File 'lib/atco/header.rb', line 26 def initialize(data) @file_type = data[:file_type] @version = data[:version] @file_originator = data[:file_originator] @source_product = data[:source_product] @production_datetime = data[:production_datetime] end |
Instance Attribute Details
#file_originator ⇒ Object
Returns the value of attribute file_originator.
6 7 8 |
# File 'lib/atco/header.rb', line 6 def file_originator @file_originator end |
#file_type ⇒ Object
Returns the value of attribute file_type.
6 7 8 |
# File 'lib/atco/header.rb', line 6 def file_type @file_type end |
#production_datetime ⇒ Object
Returns the value of attribute production_datetime.
6 7 8 |
# File 'lib/atco/header.rb', line 6 def production_datetime @production_datetime end |
#source_product ⇒ Object
Returns the value of attribute source_product.
6 7 8 |
# File 'lib/atco/header.rb', line 6 def source_product @source_product end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/atco/header.rb', line 6 def version @version end |
Class Method Details
.parse(line) ⇒ Object
Public: Parse a header line from an ATCO-CIF file. EXAMPLE: “ATCO-CIF0500Electronic Registration MIA 4.20.18 20090915113809rn”
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/atco/header.rb', line 15 def self.parse(line) data = { file_type: line[0, 8], version: "#{line[8, 2].to_i}.#{line[10, 2].to_i}", file_originator: line[12, 32].strip!, source_product: line[44, 16].strip!, production_datetime: line[60, 14] } new(data) end |
Instance Method Details
#attributes ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/atco/header.rb', line 34 def attributes { file_type: @file_type, version: @version, file_originator: @file_originator, source_product: @source_product, production_datetime: @production_datetime } end |
#to_json(*attrs) ⇒ Object
44 45 46 |
# File 'lib/atco/header.rb', line 44 def to_json(*attrs) attributes.to_json(*attrs) end |