Module: Hotfile::Transaction
- Included in:
- Hotfile
- Defined in:
- lib/hotfile/transaction.rb
Overview
Gathers transaction information from parsed data.
Instance Method Summary collapse
- #find_pnr(records) ⇒ Object
- #flight_schedule(flight_records) ⇒ Object
- #passengers(passenger_records) ⇒ Object
- #summarize_transaction(records) ⇒ Object
- #transactions ⇒ Object
Instance Method Details
#find_pnr(records) ⇒ Object
65 66 67 |
# File 'lib/hotfile/transaction.rb', line 65 def find_pnr(records) records&.first&.dig(:data, :pnr)&.split('/')&.first end |
#flight_schedule(flight_records) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hotfile/transaction.rb', line 26 def flight_schedule(flight_records) return [] unless flight_records.respond_to?(:each) flight_records.map do |record| d = record[:data] { carrier: d[:carrier], flight_number: d[:flight_number], departure: d[:departure], arrival: d[:arrival], baggage: d[:baggage], status: d[:booking][:status] } end end |
#passengers(passenger_records) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hotfile/transaction.rb', line 41 def passengers(passenger_records) return [] unless passenger_records.respond_to?(:each) passenger_records.map do |record| full_name = record[:data][:name] surname, first_name = full_name.split('/') gender = first_name.end_with?('MS') || first_name.end_with?('MRS') ? :f : :m first_name = first_name.scan(/(.*)(MS|MR|MRS)$/).flatten.first type = case record[:data][:type] when 'ADT' then :adult when 'CHD' then :child when 'INF' then :infant else :unknown end { first_name: first_name, surname: surname, gender: gender, info: record[:data][:passenger_data], date_of_birth: record[:data][:date_of_birth], type: type } end end |
#summarize_transaction(records) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hotfile/transaction.rb', line 11 def summarize_transaction(records) types = records.group_by { |x| x[:code][:number] } { transaction: records.first[:transaction], payment: { total: types[30].map { |x| x[:data][:amounts][:total] }.sum, net: types[30].map { |x| x[:data][:amounts][:net] }.sum, commissionable: types[30].map { |x| x[:data][:amounts][:commissionable] }.sum }, flight_schedule: flight_schedule(types[63]), passengers: passengers(types[65]), pnr: find_pnr(types[24]) } end |
#transactions ⇒ Object
6 7 8 9 |
# File 'lib/hotfile/transaction.rb', line 6 def transactions record_groups = parse[:records].select { |x| x[:transaction].to_i.positive? }.group_by { |x| x[:transaction] } record_groups.each_value.map { |x| summarize_transaction(x) } end |