module Eancom module Edifact class NAD < Segment TAG = 'NAD'.freeze TYPE = :body.freeze def initialize( tag: nil, party_function_code_qualifier:, party_identifier:, code_list_identification_code_1: '', code_list_responsible_agancy_code_1:, name_and_address_description_1: nil, name_and_address_description_2: nil, name_and_address_description_3: nil, name_and_address_description_4: nil, name_and_address_description_5: nil, party_name_1: nil, party_name_2: nil, party_name_3: nil, party_name_4: nil, party_name_5: nil, street_and_number_1: nil, street_and_number_2: nil, street_and_number_3: nil, street_and_number_4: nil, street_and_number_5: nil, city_name: nil, country_sub_entity_name_code: nil, code_list_identification_code_2: nil, code_list_responsible_agancy_code_2: nil, country_sub_entry_name: nil, postal_identification_code: nil, country_name_code: nil ) @tag = tag @party_function_code_qualifier = party_function_code_qualifier @party_identifier = party_identifier @code_list_identification_code_1 = code_list_identification_code_1 @code_list_responsible_agancy_code_1 = code_list_responsible_agancy_code_1 @name_and_address_description_1 = name_and_address_description_1 @name_and_address_description_2 = name_and_address_description_2 @name_and_address_description_3 = name_and_address_description_3 @name_and_address_description_4 = name_and_address_description_4 @name_and_address_description_5 = name_and_address_description_5 @party_name_1 = party_name_1 @party_name_2 = party_name_2 @party_name_3 = party_name_3 @party_name_4 = party_name_4 @party_name_5 = party_name_5 @street_and_number_1 = street_and_number_1 @street_and_number_2 = street_and_number_2 @street_and_number_3 = street_and_number_3 @street_and_number_4 = street_and_number_4 @street_and_number_5 = street_and_number_5 @city_name = city_name @country_sub_entity_name_code = country_sub_entity_name_code @code_list_identification_code_2 = code_list_identification_code_2 @code_list_responsible_agancy_code_2 = code_list_responsible_agancy_code_2 @country_sub_entry_name = country_sub_entry_name @postal_identification_code = postal_identification_code @country_name_code = country_name_code super(tag: tag || TAG) end def to_json_hash hash = { identifier => {} } hash[identifier].merge!({ party_identifier: @party_identifier }) if @party_identifier hash[identifier].merge!(code_list_responsible_agancy_code_1: find_identifier(:code_list_responsible_agancy_code_1)) if @code_list_responsible_agancy_code_1 hash[identifier].merge!({ name_and_address_description_1: @name_and_address_description_1 }) if @name_and_address_description_1 hash[identifier].merge!({ name_and_address_description_2: @name_and_address_description_2 }) if @name_and_address_description_2 hash[identifier].merge!({ name_and_address_description_3: @name_and_address_description_3 }) if @name_and_address_description_3 hash[identifier].merge!({ name_and_address_description_4: @name_and_address_description_4 }) if @name_and_address_description_4 hash[identifier].merge!({ name_and_address_description_5: @name_and_address_description_5 }) if @name_and_address_description_5 hash[identifier].merge!({ party_name_1: @party_name_1 }) if @party_name_1 hash[identifier].merge!({ party_name_2: @party_name_2 }) if @party_name_2 hash[identifier].merge!({ party_name_3: @party_name_3 }) if @party_name_3 hash[identifier].merge!({ party_name_4: @party_name_4 }) if @party_name_4 hash[identifier].merge!({ party_name_5: @party_name_5 }) if @party_name_5 hash[identifier].merge!({ street_and_number_1: @street_and_number_1 }) if @street_and_number_1 hash[identifier].merge!({ street_and_number_2: @street_and_number_2 }) if @street_and_number_2 hash[identifier].merge!({ street_and_number_3: @street_and_number_3 }) if @street_and_number_3 hash[identifier].merge!({ street_and_number_4: @street_and_number_4 }) if @street_and_number_4 hash[identifier].merge!({ street_and_number_5: @street_and_number_5 }) if @street_and_number_5 hash[identifier].merge!({ city_name: @city_name }) if @city_name hash[identifier].merge!({ country_sub_entity_name_code: @country_sub_entity_name_code }) if @country_sub_entity_name_code hash[identifier].merge!({ country_sub_entry_name: @country_sub_entry_name }) if @country_sub_entry_name hash[identifier].merge!({ postal_identification_code: @postal_identification_code }) if @postal_identification_code hash[identifier].merge!({ country_name_code: @country_name_code }) if @country_name_code hash = {} if hash[identifier].empty? hash end def segment_type TYPE end private def identifier @identifier ||= structure.find(:party_function_code_qualifier).dictionary[@party_function_code_qualifier][:identifier] end end end end