Class: Airhelp::Record

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/airhelp/record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Record

Returns a new instance of Record.



16
17
18
19
20
# File 'lib/airhelp/record.rb', line 16

def initialize(params)
  params.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#carrier_codeObject

Returns the value of attribute carrier_code.



7
8
9
# File 'lib/airhelp/record.rb', line 7

def carrier_code
  @carrier_code
end

#carrier_code_typeObject

Returns the value of attribute carrier_code_type.



7
8
9
# File 'lib/airhelp/record.rb', line 7

def carrier_code_type
  @carrier_code_type
end

#flight_dateObject

Returns the value of attribute flight_date.



7
8
9
# File 'lib/airhelp/record.rb', line 7

def flight_date
  @flight_date
end

#flight_numberObject

Returns the value of attribute flight_number.



7
8
9
# File 'lib/airhelp/record.rb', line 7

def flight_number
  @flight_number
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/airhelp/record.rb', line 7

def id
  @id
end

Class Method Details

.headers(params = nil) ⇒ Object



39
40
41
# File 'lib/airhelp/record.rb', line 39

def self.headers(params=nil)
  %w(id carrier_code carrier_code_type flight_number flight_date #{params})
end

Instance Method Details

#processObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/airhelp/record.rb', line 22

def process
  if @carrier_code =~ /\A[a-zA-Z]{3}\z/
    @carrier_code_type = 'ICAO'
  elsif @carrier_code =~ /\A[a-zA-Z]{2}\*?\z/
    @carrier_code_type = 'IATA'
  else
    @carrier_code_type = 'unknown'
    errors.add(:carrier_code_type, 'format is unknown')
  end
end

#to_aObject



33
34
35
36
37
# File 'lib/airhelp/record.rb', line 33

def to_a
  array = [id, carrier_code, carrier_code_type, flight_number, flight_date]
  array.push(errors.full_messages.join(';')) if errors.any?
  array
end