eancom 1.5.7 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/definitions/slsrpt/d01b.rb +59 -59
- data/definitions/slsrpt/d96a.rb +61 -59
- data/lib/eancom/edifact/body.rb +18 -37
- data/lib/eancom/edifact/document.rb +17 -21
- data/lib/eancom/edifact/item.rb +1 -1
- data/lib/eancom/edifact/location.rb +56 -0
- data/lib/eancom/edifact/message.rb +39 -7
- data/lib/eancom/edifact/segment.rb +4 -0
- data/lib/eancom/edifact/segments/loc.rb +4 -0
- data/lib/eancom/edifact/segments/uns.rb +1 -1
- data/lib/eancom/edifact.rb +1 -0
- data/lib/eancom/parser/document.rb +1 -1
- data/lib/eancom/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 10b8633addd1b19df008fcfbf0b33b75c2639cac939e2f2923d6518515c1e670
         | 
| 4 | 
            +
              data.tar.gz: 26a096e4e9afa9c39a0e2184dc2bd60fdf7f2f95140e70dfc19a31d59262cd27
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 34f0152b2721cf4effa65f159642077d52a1e79653e22461a9deb558894c628687775265c1f0b1ced37dfc1a41e87b47af0e6239b53325bee11190845221dd26
         | 
| 7 | 
            +
              data.tar.gz: 52974b80bc2d5bfb9b429c58f2ac01e3c1029e655c8cce924e7115c5ed4af483b56727ec18292871509f2961134683c1f7408e994fbcb7b811360820b1d1461a
         | 
    
        data/definitions/slsrpt/d01b.rb
    CHANGED
    
    | @@ -109,78 +109,78 @@ Eancom::Definition.create(name: 'D01B', type: :slsrpt) do |document, config| | |
| 109 109 | 
             
                    )
         | 
| 110 110 | 
             
                  end
         | 
| 111 111 |  | 
| 112 | 
            -
                   | 
| 113 | 
            -
                  if location = message.location
         | 
| 114 | 
            -
                    code_list_responsible_agency_code = if location.code_list_responsible_agancy_code
         | 
| 115 | 
            -
                                                          structure = Eancom.find_structure(tag: 'LOC')
         | 
| 116 | 
            -
                                                          structure.dictionary_lookup(
         | 
| 117 | 
            -
                                                            :code_list_responsible_agancy_code,
         | 
| 118 | 
            -
                                                            location.code_list_responsible_agancy_code
         | 
| 119 | 
            -
                                                          )
         | 
| 120 | 
            -
                                                        else
         | 
| 121 | 
            -
                                                          '9'
         | 
| 122 | 
            -
                                                        end
         | 
| 123 | 
            -
             | 
| 124 | 
            -
                    body.segment Eancom::Edifact::LOC.new(
         | 
| 125 | 
            -
                      code_list_identification_code: location.code_list_identification_code,
         | 
| 126 | 
            -
                      code_list_responsible_agancy_code: code_list_responsible_agency_code,
         | 
| 127 | 
            -
                      location_function_qualifier: '162',
         | 
| 128 | 
            -
                      location_name_code: location.location_name_code
         | 
| 129 | 
            -
                    )
         | 
| 130 | 
            -
                  end
         | 
| 112 | 
            +
                  item_counter = 0
         | 
| 131 113 |  | 
| 132 | 
            -
                   | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 114 | 
            +
                  message.locations.each do |location_group|
         | 
| 115 | 
            +
                    if location = location_group.location
         | 
| 116 | 
            +
                      code_list_responsible_agency_code = if location.code_list_responsible_agancy_code
         | 
| 117 | 
            +
                                                            structure = Eancom.find_structure(tag: 'LOC')
         | 
| 118 | 
            +
                                                            structure.dictionary_lookup(
         | 
| 119 | 
            +
                                                              :code_list_responsible_agancy_code,
         | 
| 120 | 
            +
                                                              location.code_list_responsible_agancy_code
         | 
| 121 | 
            +
                                                            )
         | 
| 122 | 
            +
                                                          else
         | 
| 123 | 
            +
                                                            '9'
         | 
| 124 | 
            +
                                                          end
         | 
| 143 125 |  | 
| 144 | 
            -
             | 
| 126 | 
            +
                      body.segment Eancom::Edifact::LOC.new(
         | 
| 127 | 
            +
                        code_list_identification_code: location.code_list_identification_code,
         | 
| 128 | 
            +
                        code_list_responsible_agancy_code: code_list_responsible_agency_code,
         | 
| 129 | 
            +
                        location_function_qualifier: '162',
         | 
| 130 | 
            +
                        location_name_code: location.location_name_code
         | 
| 131 | 
            +
                      )
         | 
| 132 | 
            +
                    end
         | 
| 145 133 |  | 
| 146 | 
            -
             | 
| 147 | 
            -
                     | 
| 134 | 
            +
                    # Sales Date
         | 
| 135 | 
            +
                    if date_time = location_group.sales_date_and_or_time_and_or_period&.date_time
         | 
| 136 | 
            +
                      body.segment Eancom::Edifact::DTM.new(
         | 
| 137 | 
            +
                        type: '356',
         | 
| 138 | 
            +
                        date_time: date_time,
         | 
| 139 | 
            +
                        format: '102'
         | 
| 140 | 
            +
                      )
         | 
| 141 | 
            +
                    end
         | 
| 148 142 |  | 
| 149 | 
            -
                     | 
| 150 | 
            -
             | 
| 151 | 
            -
                       | 
| 152 | 
            -
                      item_type_identification_code: 'SRV'
         | 
| 153 | 
            -
                    )
         | 
| 143 | 
            +
                    # Items
         | 
| 144 | 
            +
                    location_group.items.each do |item|
         | 
| 145 | 
            +
                      item_counter += 1
         | 
| 154 146 |  | 
| 155 | 
            -
             | 
| 156 | 
            -
             | 
| 157 | 
            -
                         | 
| 158 | 
            -
                         | 
| 147 | 
            +
                      body.segment Eancom::Edifact::LIN.new(
         | 
| 148 | 
            +
                        line_item_identifier_1: item_counter.to_s,
         | 
| 149 | 
            +
                        item_identifier: item.ean,
         | 
| 150 | 
            +
                        item_type_identification_code: 'SRV'
         | 
| 159 151 | 
             
                      )
         | 
| 160 | 
            -
                    end
         | 
| 161 152 |  | 
| 162 | 
            -
             | 
| 163 | 
            -
             | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
                        body.segment Eancom::Edifact::PRI.new(
         | 
| 167 | 
            -
                          price_amount: price.price_amount,
         | 
| 168 | 
            -
                          price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
         | 
| 169 | 
            -
                          price_specification_code: structure.dictionary_lookup(:price_specification_code, price.price_specification_code),
         | 
| 170 | 
            -
                          price_type_code: price.price_type_code
         | 
| 153 | 
            +
                      if transaction_reference_number = item.transaction_reference_number
         | 
| 154 | 
            +
                        body.segment Eancom::Edifact::RFF.new(
         | 
| 155 | 
            +
                          reference_code_qualifier: 'TN',
         | 
| 156 | 
            +
                          reference_identifier: transaction_reference_number.reference_identifier
         | 
| 171 157 | 
             
                        )
         | 
| 172 158 | 
             
                      end
         | 
| 173 | 
            -
                    end
         | 
| 174 159 |  | 
| 175 | 
            -
             | 
| 176 | 
            -
             | 
| 177 | 
            -
             | 
| 178 | 
            -
             | 
| 179 | 
            -
             | 
| 180 | 
            -
             | 
| 160 | 
            +
                      prices = item.prices
         | 
| 161 | 
            +
                      prices.each do |price_group|
         | 
| 162 | 
            +
                        if price = price_group.price
         | 
| 163 | 
            +
                          structure = Eancom.find_structure(tag: 'PRI')
         | 
| 164 | 
            +
                          body.segment Eancom::Edifact::PRI.new(
         | 
| 165 | 
            +
                            price_amount: price.price_amount,
         | 
| 166 | 
            +
                            price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
         | 
| 167 | 
            +
                            price_specification_code: structure.dictionary_lookup(:price_specification_code, price.price_specification_code),
         | 
| 168 | 
            +
                            price_type_code: price.price_type_code
         | 
| 169 | 
            +
                          )
         | 
| 170 | 
            +
                        end
         | 
| 171 | 
            +
                      end
         | 
| 172 | 
            +
             | 
| 173 | 
            +
                      # Quantity
         | 
| 174 | 
            +
                      if statistical_sales_quantitiy = item.statistical_sales_quantitiy
         | 
| 175 | 
            +
                        body.segment Eancom::Edifact::QTY.new(
         | 
| 176 | 
            +
                          quantity_type_code_qualifier: '153',
         | 
| 177 | 
            +
                          quantity: statistical_sales_quantitiy.quantity
         | 
| 178 | 
            +
                        )
         | 
| 179 | 
            +
                      end
         | 
| 181 180 | 
             
                    end
         | 
| 182 181 | 
             
                  end
         | 
| 183 182 |  | 
| 183 | 
            +
             | 
| 184 184 | 
             
                  body.segment Eancom::Edifact::UNS.new(
         | 
| 185 185 | 
             
                    section_identification: 'S'
         | 
| 186 186 | 
             
                  )
         | 
    
        data/definitions/slsrpt/d96a.rb
    CHANGED
    
    | @@ -106,78 +106,80 @@ Eancom::Definition.create(name: 'D96A', type: :slsrpt) do |document, config| | |
| 106 106 | 
             
                    )
         | 
| 107 107 | 
             
                  end
         | 
| 108 108 |  | 
| 109 | 
            -
                   | 
| 110 | 
            -
                  if location = message.location
         | 
| 111 | 
            -
                    code_list_responsible_agency_code = if location.code_list_responsible_agancy_code
         | 
| 112 | 
            -
                                                          structure = Eancom.find_structure(tag: 'LOC')
         | 
| 113 | 
            -
                                                          structure.dictionary_lookup(
         | 
| 114 | 
            -
                                                            :code_list_responsible_agancy_code,
         | 
| 115 | 
            -
                                                            location.code_list_responsible_agancy_code
         | 
| 116 | 
            -
                                                          )
         | 
| 117 | 
            -
                                                        else
         | 
| 118 | 
            -
                                                          '9'
         | 
| 119 | 
            -
                                                        end
         | 
| 120 | 
            -
                    body.segment Eancom::Edifact::LOC.new(
         | 
| 121 | 
            -
                      code_list_identification_code: location.code_list_identification_code,
         | 
| 122 | 
            -
                      code_list_responsible_agancy_code: code_list_responsible_agency_code,
         | 
| 123 | 
            -
                      location_function_qualifier: '150',
         | 
| 124 | 
            -
                      location_name_code: location.location_name_code
         | 
| 125 | 
            -
                    )
         | 
| 126 | 
            -
                  end
         | 
| 127 | 
            -
             | 
| 128 | 
            -
                  # Sales Date
         | 
| 129 | 
            -
                  if date_time = message.sales_date_and_or_time_and_or_period.date_time
         | 
| 130 | 
            -
                    body.segment Eancom::Edifact::DTM.new(
         | 
| 131 | 
            -
                      type: '356',
         | 
| 132 | 
            -
                      date_time: date_time,
         | 
| 133 | 
            -
                      format: '203'
         | 
| 134 | 
            -
                    )
         | 
| 135 | 
            -
                  end
         | 
| 109 | 
            +
                  item_counter = 0
         | 
| 136 110 |  | 
| 137 | 
            -
                   | 
| 138 | 
            -
                  total_quantity = 0
         | 
| 111 | 
            +
                  message.locations.each do |location_group|
         | 
| 139 112 |  | 
| 140 | 
            -
             | 
| 113 | 
            +
                    # Location
         | 
| 114 | 
            +
                    if location = location_group.location
         | 
| 115 | 
            +
                      code_list_responsible_agency_code = if location.code_list_responsible_agancy_code
         | 
| 116 | 
            +
                                                            structure = Eancom.find_structure(tag: 'LOC')
         | 
| 117 | 
            +
                                                            structure.dictionary_lookup(
         | 
| 118 | 
            +
                                                              :code_list_responsible_agancy_code,
         | 
| 119 | 
            +
                                                              location.code_list_responsible_agancy_code
         | 
| 120 | 
            +
                                                            )
         | 
| 121 | 
            +
                                                          else
         | 
| 122 | 
            +
                                                            '9'
         | 
| 123 | 
            +
                                                          end
         | 
| 124 | 
            +
                      body.segment Eancom::Edifact::LOC.new(
         | 
| 125 | 
            +
                        code_list_identification_code: location.code_list_identification_code,
         | 
| 126 | 
            +
                        code_list_responsible_agancy_code: code_list_responsible_agency_code,
         | 
| 127 | 
            +
                        location_function_qualifier: '150',
         | 
| 128 | 
            +
                        location_name_code: location.location_name_code
         | 
| 129 | 
            +
                      )
         | 
| 130 | 
            +
                    end
         | 
| 141 131 |  | 
| 142 | 
            -
             | 
| 143 | 
            -
                     | 
| 132 | 
            +
                    # Sales Date
         | 
| 133 | 
            +
                    if date_time = location_group.sales_date_and_or_time_and_or_period&.date_time
         | 
| 134 | 
            +
                      body.segment Eancom::Edifact::DTM.new(
         | 
| 135 | 
            +
                        type: '356',
         | 
| 136 | 
            +
                        date_time: date_time,
         | 
| 137 | 
            +
                        format: '203'
         | 
| 138 | 
            +
                      )
         | 
| 139 | 
            +
                    end
         | 
| 144 140 |  | 
| 145 | 
            -
                     | 
| 146 | 
            -
             | 
| 147 | 
            -
                       | 
| 148 | 
            -
                      item_type_identification_code: 'EN'
         | 
| 149 | 
            -
                    )
         | 
| 141 | 
            +
                    # Items
         | 
| 142 | 
            +
                    location_group.items.each do |item|
         | 
| 143 | 
            +
                      item_counter += 1
         | 
| 150 144 |  | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
                         | 
| 154 | 
            -
                         | 
| 145 | 
            +
                      body.segment Eancom::Edifact::LIN.new(
         | 
| 146 | 
            +
                        line_item_identifier_1: item_counter.to_s,
         | 
| 147 | 
            +
                        item_identifier: item.ean,
         | 
| 148 | 
            +
                        item_type_identification_code: 'EN'
         | 
| 155 149 | 
             
                      )
         | 
| 156 | 
            -
                    end
         | 
| 157 150 |  | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
             | 
| 161 | 
            -
             | 
| 162 | 
            -
                        body.segment Eancom::Edifact::PRI.new(
         | 
| 163 | 
            -
                          price_amount: price.price_amount,
         | 
| 164 | 
            -
                          price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
         | 
| 165 | 
            -
                          price_specification_code: structure.dictionary_lookup(:price_specification_code, price.price_specification_code),
         | 
| 166 | 
            -
                          price_type_code: price.price_type_code
         | 
| 151 | 
            +
                      if transaction_reference_number = item.transaction_reference_number
         | 
| 152 | 
            +
                        body.segment Eancom::Edifact::RFF.new(
         | 
| 153 | 
            +
                          reference_code_qualifier: 'TN',
         | 
| 154 | 
            +
                          reference_identifier: transaction_reference_number.reference_identifier
         | 
| 167 155 | 
             
                        )
         | 
| 168 156 | 
             
                      end
         | 
| 169 | 
            -
                    end
         | 
| 170 157 |  | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 173 | 
            -
             | 
| 174 | 
            -
             | 
| 175 | 
            -
             | 
| 176 | 
            -
             | 
| 177 | 
            -
             | 
| 158 | 
            +
                      prices = item.prices
         | 
| 159 | 
            +
                      prices.each do |price|
         | 
| 160 | 
            +
                        if price = price.price
         | 
| 161 | 
            +
                          structure = Eancom.find_structure(tag: 'PRI')
         | 
| 162 | 
            +
                          body.segment Eancom::Edifact::PRI.new(
         | 
| 163 | 
            +
                            price_amount: price.price_amount,
         | 
| 164 | 
            +
                            price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
         | 
| 165 | 
            +
                            price_specification_code: structure.dictionary_lookup(:price_specification_code, price.price_specification_code),
         | 
| 166 | 
            +
                            price_type_code: price.price_type_code
         | 
| 167 | 
            +
                          )
         | 
| 168 | 
            +
                        end
         | 
| 169 | 
            +
                      end
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                      # Quantity
         | 
| 172 | 
            +
                      if minimum_production_batch = item.minimum_production_batch
         | 
| 173 | 
            +
                        body.segment Eancom::Edifact::QTY.new(
         | 
| 174 | 
            +
                          quantity_type_code_qualifier: '160',
         | 
| 175 | 
            +
                          quantity: minimum_production_batch.quantity,
         | 
| 176 | 
            +
                          measurement_unit_code: 'PCE'
         | 
| 177 | 
            +
                        )
         | 
| 178 | 
            +
                      end
         | 
| 178 179 | 
             
                    end
         | 
| 179 180 | 
             
                  end
         | 
| 180 181 |  | 
| 182 | 
            +
             | 
| 181 183 | 
             
                  body.segment Eancom::Edifact::UNT.new(
         | 
| 182 184 | 
             
                    number_of_segments_in_message: "#{document.total_segments + 2}",
         | 
| 183 185 | 
             
                    message_reference_number: config.header.message_reference_number,
         | 
    
        data/lib/eancom/edifact/body.rb
    CHANGED
    
    | @@ -1,8 +1,9 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Eancom
         | 
| 2 4 | 
             
              module Edifact
         | 
| 3 5 | 
             
                class Body < DocumentElement
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                  attr_accessor :hash, :items, :messages
         | 
| 6 | 
            +
                  attr_accessor :hash, :messages, :locations, :items
         | 
| 6 7 |  | 
| 7 8 | 
             
                  def initialize
         | 
| 8 9 | 
             
                    super
         | 
| @@ -11,52 +12,32 @@ module Eancom | |
| 11 12 | 
             
                  end
         | 
| 12 13 |  | 
| 13 14 | 
             
                  def to_json_hash
         | 
| 14 | 
            -
                    @ | 
| 15 | 
            -
                      start_message(segment) if segment.starts_message?
         | 
| 16 | 
            -
                      start_item(segment) if segment.starts_item?
         | 
| 17 | 
            -
                      if @item
         | 
| 18 | 
            -
                        @item << segment
         | 
| 19 | 
            -
                      else
         | 
| 20 | 
            -
                        @message << segment
         | 
| 21 | 
            -
                      end
         | 
| 22 | 
            -
                    end
         | 
| 23 | 
            -
                    @message.add_item(@item.to_json_hash)
         | 
| 24 | 
            -
                    @messages << @message.to_json_hash
         | 
| 25 | 
            -
                    hash.merge!({ messages: messages })
         | 
| 26 | 
            -
                    { body: hash }
         | 
| 15 | 
            +
                    @to_json_hash ||= build_json_hash
         | 
| 27 16 | 
             
                  end
         | 
| 28 17 |  | 
| 29 | 
            -
                  def start_message | 
| 18 | 
            +
                  def start_message
         | 
| 30 19 | 
             
                    if @message
         | 
| 31 20 | 
             
                      @messages << @message.to_json_hash
         | 
| 32 | 
            -
                      if @item && !@item.empty?
         | 
| 33 | 
            -
                        @message.add_item(@item.to_json_hash)
         | 
| 34 | 
            -
                      end
         | 
| 35 | 
            -
                      @item = nil
         | 
| 36 | 
            -
                    end
         | 
| 37 | 
            -
                    @message = Eancom::Edifact::Message.new()
         | 
| 38 | 
            -
                  end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                  def start_item(segment)
         | 
| 41 | 
            -
                    if @item && !@item.empty?
         | 
| 42 | 
            -
                      @message.add_item(@item.to_json_hash)
         | 
| 43 21 | 
             
                    end
         | 
| 44 | 
            -
                    @ | 
| 22 | 
            +
                    @message = Eancom::Edifact::Message.new
         | 
| 45 23 | 
             
                  end
         | 
| 46 24 |  | 
| 47 25 | 
             
                  private
         | 
| 48 26 |  | 
| 49 | 
            -
                  def  | 
| 50 | 
            -
                     | 
| 51 | 
            -
                      hash[name] = [] if hash[name].nil?
         | 
| 52 | 
            -
                      hash[name] << segment.to_json_hash
         | 
| 53 | 
            -
                    else
         | 
| 54 | 
            -
                      hash.merge!(segment.to_json_hash)
         | 
| 55 | 
            -
                    end
         | 
| 27 | 
            +
                  def group_name(segment)
         | 
| 28 | 
            +
                    segment.group_name
         | 
| 56 29 | 
             
                  end
         | 
| 57 30 |  | 
| 58 | 
            -
                  def  | 
| 59 | 
            -
                     | 
| 31 | 
            +
                  def build_json_hash
         | 
| 32 | 
            +
                    @segments.each do |segment|
         | 
| 33 | 
            +
                      start_message if segment.starts_message?
         | 
| 34 | 
            +
                      @message << segment
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
                    messages << @message.to_json_hash
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    {
         | 
| 39 | 
            +
                      body: hash.merge({ messages: messages })
         | 
| 40 | 
            +
                    }
         | 
| 60 41 | 
             
                  end
         | 
| 61 42 | 
             
                end
         | 
| 62 43 | 
             
              end
         | 
| @@ -1,25 +1,25 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Eancom
         | 
| 2 4 | 
             
              module Edifact
         | 
| 3 5 | 
             
                class Document
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                  attr_accessor :header_element,
         | 
| 6 | 
            -
                    :body_element, :footer_element
         | 
| 6 | 
            +
                  attr_accessor :header_element, :body_element, :footer_element
         | 
| 7 7 |  | 
| 8 8 | 
             
                  def initialize
         | 
| 9 | 
            -
                    @header_element = Header.new | 
| 10 | 
            -
                    @body_element = Body.new | 
| 11 | 
            -
                    @footer_element = Footer.new | 
| 9 | 
            +
                    @header_element = Header.new
         | 
| 10 | 
            +
                    @body_element = Body.new
         | 
| 11 | 
            +
                    @footer_element = Footer.new
         | 
| 12 12 | 
             
                  end
         | 
| 13 13 |  | 
| 14 | 
            -
                  def header | 
| 14 | 
            +
                  def header
         | 
| 15 15 | 
             
                    yield(@header_element)
         | 
| 16 16 | 
             
                  end
         | 
| 17 17 |  | 
| 18 | 
            -
                  def body | 
| 18 | 
            +
                  def body
         | 
| 19 19 | 
             
                    yield(@body_element)
         | 
| 20 20 | 
             
                  end
         | 
| 21 21 |  | 
| 22 | 
            -
                  def footer | 
| 22 | 
            +
                  def footer
         | 
| 23 23 | 
             
                    yield(@footer_element)
         | 
| 24 24 | 
             
                  end
         | 
| 25 25 |  | 
| @@ -42,18 +42,14 @@ module Eancom | |
| 42 42 | 
             
                  end
         | 
| 43 43 |  | 
| 44 44 | 
             
                  def to_s(debug: false)
         | 
| 45 | 
            -
                     | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
                     | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
                    hash = {}
         | 
| 54 | 
            -
                    hash.merge! @header_element.to_json_hash
         | 
| 55 | 
            -
                    hash.merge! @body_element.to_json_hash
         | 
| 56 | 
            -
                    hash.to_json
         | 
| 45 | 
            +
                    "#{@header_element.to_s(debug: debug)}#{@body_element.to_s(debug: debug)}#{@footer_element.to_s(debug: debug)}"
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def to_json(_obj = nil)
         | 
| 49 | 
            +
                    {
         | 
| 50 | 
            +
                      **@header_element.to_json_hash,
         | 
| 51 | 
            +
                      **@body_element.to_json_hash
         | 
| 52 | 
            +
                    }.to_json
         | 
| 57 53 | 
             
                  end
         | 
| 58 54 | 
             
                end
         | 
| 59 55 | 
             
              end
         | 
    
        data/lib/eancom/edifact/item.rb
    CHANGED
    
    
| @@ -0,0 +1,56 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Eancom
         | 
| 4 | 
            +
              module Edifact
         | 
| 5 | 
            +
                class Location
         | 
| 6 | 
            +
                  attr_accessor :items, :hash
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize
         | 
| 9 | 
            +
                    @items = []
         | 
| 10 | 
            +
                    @hash = {}
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def add_item(item)
         | 
| 14 | 
            +
                    @items << item
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def <<(segment)
         | 
| 18 | 
            +
                    start_item if segment.starts_item?
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    if @item
         | 
| 21 | 
            +
                      @item << segment
         | 
| 22 | 
            +
                    elsif name = group_name(segment)
         | 
| 23 | 
            +
                      @hash[name] = [] if @hash[name].nil?
         | 
| 24 | 
            +
                      @hash[name] << segment.to_json_hash
         | 
| 25 | 
            +
                    else
         | 
| 26 | 
            +
                      @hash.merge!(segment.to_json_hash)
         | 
| 27 | 
            +
                    end
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def to_json_hash
         | 
| 31 | 
            +
                    if @item && !@item.empty?
         | 
| 32 | 
            +
                      add_item(@item.to_json_hash)
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    @hash.merge({ items: @items })
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  def empty?
         | 
| 39 | 
            +
                    @hash.empty?
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  def start_item
         | 
| 43 | 
            +
                    if @item && !@item.empty?
         | 
| 44 | 
            +
                      add_item(@item.to_json_hash)
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
                    @item = Eancom::Edifact::Item.new
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  private
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  def group_name(segment)
         | 
| 52 | 
            +
                    segment.item_group_name || segment.group_name
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
            end
         | 
| @@ -1,20 +1,33 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module Eancom
         | 
| 2 4 | 
             
              module Edifact
         | 
| 3 5 | 
             
                class Message
         | 
| 6 | 
            +
                  attr_accessor :locations, :items, :hash
         | 
| 4 7 |  | 
| 5 | 
            -
                   | 
| 6 | 
            -
             | 
| 7 | 
            -
                  def initialize()
         | 
| 8 | 
            +
                  def initialize
         | 
| 9 | 
            +
                    @locations = []
         | 
| 8 10 | 
             
                    @items = []
         | 
| 9 11 | 
             
                    @hash = {}
         | 
| 10 12 | 
             
                  end
         | 
| 11 13 |  | 
| 14 | 
            +
                  def add_location(location)
         | 
| 15 | 
            +
                    @locations << location
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 12 18 | 
             
                  def add_item(item)
         | 
| 13 19 | 
             
                    @items << item
         | 
| 14 20 | 
             
                  end
         | 
| 15 21 |  | 
| 16 | 
            -
                  def << | 
| 17 | 
            -
                    if  | 
| 22 | 
            +
                  def <<(segment)
         | 
| 23 | 
            +
                    start_location if segment.starts_location?
         | 
| 24 | 
            +
                    start_item if segment.starts_item?
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    if @location
         | 
| 27 | 
            +
                      @location << segment
         | 
| 28 | 
            +
                    elsif @item
         | 
| 29 | 
            +
                      @item << segment
         | 
| 30 | 
            +
                    elsif name = group_name(segment)
         | 
| 18 31 | 
             
                      @hash[name] = [] if @hash[name].nil?
         | 
| 19 32 | 
             
                      @hash[name] << segment.to_json_hash
         | 
| 20 33 | 
             
                    else
         | 
| @@ -23,10 +36,16 @@ module Eancom | |
| 23 36 | 
             
                  end
         | 
| 24 37 |  | 
| 25 38 | 
             
                  def to_json_hash
         | 
| 39 | 
            +
                    if @location && !@location.empty?
         | 
| 40 | 
            +
                      add_location(@location.to_json_hash)
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
                    if @item && !@item.empty?
         | 
| 43 | 
            +
                      add_item(@item.to_json_hash)
         | 
| 44 | 
            +
                    end
         | 
| 26 45 | 
             
                    message_hash = {}
         | 
| 27 | 
            -
                    items_hash = { items: @items }
         | 
| 28 46 | 
             
                    message_hash.merge!(@hash)
         | 
| 29 | 
            -
                    message_hash.merge!( | 
| 47 | 
            +
                    message_hash.merge!({ locations: @locations }) if !@locations.empty?
         | 
| 48 | 
            +
                    message_hash.merge!({ items: @items }) if !@items.empty?
         | 
| 30 49 | 
             
                    message_hash
         | 
| 31 50 | 
             
                  end
         | 
| 32 51 |  | 
| @@ -36,6 +55,19 @@ module Eancom | |
| 36 55 | 
             
                    segment.group_name
         | 
| 37 56 | 
             
                  end
         | 
| 38 57 |  | 
| 58 | 
            +
                  def start_location
         | 
| 59 | 
            +
                    if @location && !@location.empty?
         | 
| 60 | 
            +
                      add_location(@location.to_json_hash)
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                    @location = Eancom::Edifact::Location.new
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  def start_item
         | 
| 66 | 
            +
                    if @item && !@item.empty?
         | 
| 67 | 
            +
                      add_item(@item.to_json_hash)
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
                    @item = Eancom::Edifact::Item.new
         | 
| 70 | 
            +
                  end
         | 
| 39 71 | 
             
                end
         | 
| 40 72 | 
             
              end
         | 
| 41 73 | 
             
            end
         | 
    
        data/lib/eancom/edifact.rb
    CHANGED
    
    | @@ -3,6 +3,7 @@ require 'eancom/edifact/segment' | |
| 3 3 | 
             
            require 'eancom/edifact/document_element'
         | 
| 4 4 | 
             
            require 'eancom/edifact/header'
         | 
| 5 5 | 
             
            require 'eancom/edifact/message'
         | 
| 6 | 
            +
            require 'eancom/edifact/location'
         | 
| 6 7 | 
             
            require 'eancom/edifact/item'
         | 
| 7 8 | 
             
            require 'eancom/edifact/body'
         | 
| 8 9 | 
             
            require 'eancom/edifact/footer'
         | 
    
        data/lib/eancom/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: eancom
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.6.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Fadendaten GmbH
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-05- | 
| 11 | 
            +
            date: 2023-05-15 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: pry
         | 
| @@ -190,6 +190,7 @@ files: | |
| 190 190 | 
             
            - lib/eancom/edifact/footer.rb
         | 
| 191 191 | 
             
            - lib/eancom/edifact/header.rb
         | 
| 192 192 | 
             
            - lib/eancom/edifact/item.rb
         | 
| 193 | 
            +
            - lib/eancom/edifact/location.rb
         | 
| 193 194 | 
             
            - lib/eancom/edifact/message.rb
         | 
| 194 195 | 
             
            - lib/eancom/edifact/segment.rb
         | 
| 195 196 | 
             
            - lib/eancom/edifact/segments/alc.rb
         |