Skip to content

Instantly share code, notes, and snippets.

@ewildgoose
Created August 3, 2015 12:10
Show Gist options
  • Save ewildgoose/9793fff12e4092e75383 to your computer and use it in GitHub Desktop.
Save ewildgoose/9793fff12e4092e75383 to your computer and use it in GitHub Desktop.
# column :record_type, 2, :type => :integer
# column :sender, 5
# column :recipient, 5
# column :sequence, 5, :type => :integer
# column :tax_treatment, 1
# column :tax_rate, 32, :type => :integer
# spacer 13
# column :file_creation_date, 6, :type => :date, :format => '%y%m%d'
# column :file_transmission_date, 6, :type => :date, :format => '%y%m%d'
# column :cutoff_time, 12, :type => :string, :format => '%y%m%d%H%M%S'
# column :utc_offset, 5, :type => :int
# 10-header
# column :version, 2, :type => :int
# column :international_access_code, 12, :type => :string
# column :country_code, 8, :type => :string
# spacer 46
def parse_record(<< "10",
sender::binary-size(5),
recipient::binary-size(5),
sequence::binary-size(5),
tax_treatment::binary-size(1),
tax_rate_1::binary-size(4),
tax_rate_2::binary-size(4),
tax_rate_3::binary-size(4),
tax_rate_4::binary-size(4),
tax_rate_5::binary-size(4),
tax_rate_6::binary-size(4),
tax_rate_7::binary-size(4),
tax_rate_8::binary-size(4),
_ ::binary-size(13),
file_creation_date::binary-size(6),
file_transmission_date::binary-size(6),
cutoff_time::binary-size(12),
utc_offset::binary-size(5),
version::binary-size(2),
international_access_code::binary-size(12),
country_code_1::binary-size(4),
country_code_2::binary-size(4),
_ ::binary-size(46),
rest::binary>>)
do
s = %Tap2.Header{
sender: sender |> convert(:string,[]),
recipient: recipient |> convert(:string,[]),
sequence: sequence |> convert(:integer,[]),
tax_treatment: tax_treatment |> convert(:string,[]),
tax_rates: [ tax_rate_1 |> convert(:integer,[]),
tax_rate_2 |> convert(:integer,[]),
tax_rate_3 |> convert(:integer,[]),
tax_rate_4 |> convert(:integer,[]),
tax_rate_5 |> convert(:integer,[]),
tax_rate_6 |> convert(:integer,[]),
tax_rate_7 |> convert(:integer,[]),
tax_rate_8 |> convert(:integer,[]) ],
file_creation_date: file_creation_date |> convert(:date, [format: "%y%m%d"]),
file_transmission_date: file_transmission_date |> convert(:date, [format: "%y%m%d"]),
cutoff_time: cutoff_time |> convert(:datetime, [format: "%y%m%d%H%M%S"]),
utc_offset: utc_offset |> convert(:string,[]),
version: version |> convert(:integer,[]),
international_access_code: international_access_code |> convert(:string,[]),
country_codes: [country_code_1 |> convert(:string,[]),
country_code_2 |> convert(:string,[])]
}
{s, rest}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment