Class: EDI::Interchange

Inherits:
Object
  • Object
show all
Defined in:
lib/edi/edi2json.rb

Instance Method Summary collapse

Instance Method Details

#to_hashObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/edi/edi2json.rb', line 69

def to_hash
  
  messages = []
  self.each { |message|
    if message.is_a?(MsgGroup)
      messages += message.to_hash
    else
      messages << {message.name => message.to_hash}
    end
  }
  
  {
    'UNA'            => self.una.to_hash,
    'sender'         => self.header.cS002.d0004,
    'sender_qual'    => self.header.cS002.d0007,
    'recipient'      => self.header.cS003.d0010,
    'recipient_qual' => self.header.cS003.d0007,
    'header'         => [self.header.name, self.header.to_hash],
    'body'           => messages,
    'trailer'        => [self.trailer.name, self.trailer.to_hash]
  }
end