Class: Airhelp::Record
- Inherits:
-
Object
- Object
- Airhelp::Record
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/airhelp/record.rb
Instance Attribute Summary collapse
-
#carrier_code ⇒ Object
Returns the value of attribute carrier_code.
-
#carrier_code_type ⇒ Object
Returns the value of attribute carrier_code_type.
-
#flight_date ⇒ Object
Returns the value of attribute flight_date.
-
#flight_number ⇒ Object
Returns the value of attribute flight_number.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ Record
constructor
A new instance of Record.
- #process ⇒ Object
- #to_a ⇒ Object
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_code ⇒ Object
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_type ⇒ Object
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_date ⇒ Object
Returns the value of attribute flight_date.
7 8 9 |
# File 'lib/airhelp/record.rb', line 7 def flight_date @flight_date end |
#flight_number ⇒ Object
Returns the value of attribute flight_number.
7 8 9 |
# File 'lib/airhelp/record.rb', line 7 def flight_number @flight_number end |
#id ⇒ Object
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
#process ⇒ Object
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_a ⇒ Object
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..join(';')) if errors.any? array end |