Class: Atco::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/atco/header.rb

Overview

Atco::Header is a class to abstract ATCO-CIF Header data.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_originatorObject

Returns the value of attribute file_originator.



6
7
8
# File 'lib/atco/header.rb', line 6

def file_originator
  @file_originator
end

#file_typeObject

Returns the value of attribute file_type.



6
7
8
# File 'lib/atco/header.rb', line 6

def file_type
  @file_type
end

#production_datetimeObject

Returns the value of attribute production_datetime.



6
7
8
# File 'lib/atco/header.rb', line 6

def production_datetime
  @production_datetime
end

#source_productObject

Returns the value of attribute source_product.



6
7
8
# File 'lib/atco/header.rb', line 6

def source_product
  @source_product
end

#versionObject

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

#attributesObject



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