Class: Hotfile::Record::BKS31

Inherits:
Hotfile::Record show all
Defined in:
lib/hotfile/record/BKS31.rb

Overview

Coupon Tax Information Record ! not tested, I hope this code works at all…

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ BKS31

Returns a new instance of BKS31.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hotfile/record/BKS31.rb', line 8

def initialize(line)
  super

  segment1, coupon_airport1, segment_airport1, tax_code1, tax_type1, tax_amount1, tax_currency1, tax_amount_a1,
      segment2, coupon_airport2, segment_airport2, tax_code2, tax_type2, tax_amount2, tax_currency2,
      tax_amount_a2, reserved, currency =
    line.scan(/
      (\d)
      ([A-Z ]{5})
      ([A-Z ]{6})
      ([A-Z0-9]{2})
      ([A-Z0-9 ]{3})
      (\d{10}.)
      ([A-Z0-9 ]{4})
      ([\d ]{10}.)
      (\d)
      ([A-Z ]{5})
      ([A-Z ]{6})
      ([A-Z0-9]{2})
      ([A-Z0-9 ]{3})
      (\d{10}.)
      ([A-Z0-9 ]{4})
      ([\d ]{10}.)
      (.{6})
      ([A-Z0-9]{4})
    /x).flatten

  @data = {
    currency: currency.strip,
    coupons: [
      {
        segment: segment1.strip,
        segment_airport: segment_airport1.strip,
        coupon_tax: {
          currency: tax_currency1.strip,
          airport: coupon_airport1.strip,
          code: tax_code1.strip,
          type: tax_type1.strip,
          amount: Hotfile::Integer.new(tax_amount1).to_i,
          applicable_amount: Hotfile::Integer.new(tax_amount_a1).to_i
        }
      },
      {
        segment: segment2.strip,
        segment_airport: segment_airport2.strip,
        coupon_tax: {
          currency: tax_currency2.strip,
          airport: coupon_airport2.strip,
          code: tax_code2.strip,
          type: tax_type2.strip,
          amount: Hotfile::Integer.new(tax_amount2).to_i,
          applicable_amount: Hotfile::Integer.new(tax_amount_a2).to_i
        }
      }
    ].reject { |x| x[:segment] == '' },
    reserved: reserved.strip
  }
end