Class: X12edi::EightThirtyFive
Overview
X12Edi::EightThirtyFive.new(File.read(“test/sample.edi”)).to_h
{
payer_name: "Name of Payer",
payee_name: "Name of Payee",
…, }
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from X12edi::Base
Instance Method Details
#to_h ⇒ Object
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 66 67 68 69 70 71 72 |
# File 'lib/x12edi.rb', line 40 def to_h results = {} parser.first .flatmap{|m| m.find(:GS) } .tap do |m| el(m, 2) { |e| results[:gateway] = e } end .flatmap{|m| m.find(:ST) } .tap do |m| el(m.find(:N1, "PR"), 2) {|e| results[:payer_name] = e } el(m.find(:N1, "PE"), 2) {|e| results[:payee_name] = e } end .flatmap{|m| m.find(:LX) } .flatmap{|m| m.find(:CLP) } .flatmap{|m| m.find(:NM1, "QC") } .tap do |m| el(m, 3, 4) {|l,f| results[:patient] = "#{l}, #{f}"} end .flatmap { |m| m.find(:PER) } .tap do |m| el(m, 2, 4) { |a,b| results[:payer_contact] = "Name: #{a}, Phone: #{b}"} end .flatmap { |m| m.find(:AMT) } .tap do |m| el(m, 1, 2) { |a,b| results[:amount_currency] = a results[:amount_amount] = b.to_f } end results end |