Skip to content

Commit

Permalink
fix issue #87
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Jan 11, 2024
1 parent 030863a commit b18bb64
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 17 deletions.
13 changes: 10 additions & 3 deletions lib/relaton_bib/hash_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize,Metrics/Metho
when :street, :city, :state, :country, :postcode # it's for old version compatibility, should be removed in the future
a[:street] = RelatonBib.array(a[:street])
Address.new(**a)
when :address
a[:address][:street] = RelatonBib.array(a[:address][:street])
Address.new(**a[:address])
when :address then create_address(a[:address])
when :phone, :email, :uri
Contact.new(type: type.to_s, value: value, subtype: a[:type])
else # it's for old version compatibility, should be removed in the future
Expand All @@ -319,6 +317,15 @@ def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize,Metrics/Metho
end
end

def create_address(adr)
if adr.is_a?(Hash)
adr[:street] = RelatonBib.array(adr[:street])
Address.new(**adr)
else
Address.new(formatted_address: adr)
end
end

# @param ret [Hash]
def copyright_hash_to_bib(ret)
return unless ret[:copyright]
Expand Down
18 changes: 12 additions & 6 deletions lib/relaton_bib/renderer/bibxml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,10 @@ def render_authors(builder) # rubocop:disable Metrics/AbcSize
# @param [RelatonBib::ContributionInfo] contrib contributor
#
def render_address(builder, contrib) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# addr = contrib.entity.contact.reject do |cn|
# cn.is_a?(Address) && cn.postcode.nil?
# end
if contrib.entity.contact.any?
address, contact = address_contact contrib.entity.contact
if address || contact.any?
builder.address do |xml|
address = contrib.entity.contact.detect { |cn| cn.is_a? Address }
# address = contrib.entity.contact.detect { |cn| cn.is_a? Address }
if address
xml.postal do
xml.city address.city if address.city
Expand All @@ -139,11 +137,19 @@ def render_address(builder, contrib) # rubocop:disable Metrics/AbcSize, Metrics/
xml.street address.street[0] if address.street.any?
end
end
render_contact xml, contrib.entity.contact
render_contact xml, contact
end
end
end

def address_contact(contact) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
addr = contact.detect do |c|
c.is_a?(Address) && (c.city || c.postcode || c.country || c.state || c.street.any?)
end
cont = contact.select { |c| c.is_a?(Contact) }
[addr, cont]
end

#
# Render contact
#
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_bib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonBib
VERSION = "1.18.0".freeze
VERSION = "1.18.1".freeze
end
2 changes: 2 additions & 0 deletions spec/examples/asciibib.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ contributor.organization.name:: Institute of Electrical and Electronics Engineer
contributor.organization.abbreviation:: IEEE
contributor.organization.identifier.type:: uri
contributor.organization.identifier.value:: www.ieee.org
contributor.organization.address.formatted_address:: Formatted address
contributor.role::
contributor.role.description:: Publisher description
contributor.role.type:: publisher
Expand Down Expand Up @@ -245,6 +246,7 @@ contributor.person.name.surname.script:: Latn
contributor.role.type:: editor
contributor::
contributor.organization.name:: World Wide Web Consortium
contributor.organization.address.formatted_address:: Address string
contributor.role.description:: sponsor
contributor.role.type:: distributor
relation::
Expand Down
8 changes: 7 additions & 1 deletion spec/examples/bib_item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<bibitem id="ISOTC211" type="standard" schema-version="v1.2.8">
<fetched>2024-01-05</fetched>
<fetched>2024-01-10</fetched>
<title type="title-main" format="text/plain">Geographic information</title>
<title type="main" format="text/plain">Geographic information</title>
<title format="text/plain" language="fr" script="Latn">Information géographique</title>
Expand Down Expand Up @@ -78,6 +78,9 @@
<name>Institute of Electrical and Electronics Engineers</name>
<abbreviation>IEEE</abbreviation>
<identifier type="uri">www.ieee.org</identifier>
<address>
<formattedAddress>Formatted address</formattedAddress>
</address>
</organization>
</contributor>
<contributor>
Expand Down Expand Up @@ -126,6 +129,9 @@
</role>
<organization>
<name>World Wide Web Consortium</name>
<address>
<formattedAddress>Address string</formattedAddress>
</address>
</organization>
</contributor>
<edition number="1.2">Edition 1</edition>
Expand Down
5 changes: 5 additions & 0 deletions spec/examples/bib_item.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ contributor:
identifier:
type: uri
id: www.ieee.org
contact:
address:
formatted_address: Formatted address
role:
- type: publisher
description: Publisher description
Expand Down Expand Up @@ -205,6 +208,8 @@ contributor:

- organization:
name: World Wide Web Consortium
contact:
address: Address string
role:
type: distributor
description: sponsor
Expand Down
8 changes: 7 additions & 1 deletion spec/examples/bibdata_item.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<bibdata type="standard" schema-version="v1.2.8">
<fetched>2024-01-05</fetched>
<fetched>2024-01-10</fetched>
<title type="title-main" format="text/plain">Geographic information</title>
<title type="main" format="text/plain">Geographic information</title>
<title format="text/plain" language="fr" script="Latn">Information géographique</title>
Expand Down Expand Up @@ -78,6 +78,9 @@
<name>Institute of Electrical and Electronics Engineers</name>
<abbreviation>IEEE</abbreviation>
<identifier type="uri">www.ieee.org</identifier>
<address>
<formattedAddress>Formatted address</formattedAddress>
</address>
</organization>
</contributor>
<contributor>
Expand Down Expand Up @@ -126,6 +129,9 @@
</role>
<organization>
<name>World Wide Web Consortium</name>
<address>
<formattedAddress>Address string</formattedAddress>
</address>
</organization>
</contributor>
<edition number="1.2">Edition 1</edition>
Expand Down
8 changes: 7 additions & 1 deletion spec/examples/bibdata_item_fr.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<bibdata type="standard" schema-version="v1.2.8">
<fetched>2024-01-05</fetched>
<fetched>2024-01-10</fetched>
<title format="text/plain" language="fr" script="Latn">Information géographique</title>
<uri type="src" language="en" script="Latn">https://www.iso.org/standard/53798.html</uri>
<uri type="obp">https://www.iso.org/obp/ui/#!iso:std:53798:en</uri>
Expand Down Expand Up @@ -76,6 +76,9 @@
<name>Institute of Electrical and Electronics Engineers</name>
<abbreviation>IEEE</abbreviation>
<identifier type="uri">www.ieee.org</identifier>
<address>
<formattedAddress>Formatted address</formattedAddress>
</address>
</organization>
</contributor>
<contributor>
Expand Down Expand Up @@ -124,6 +127,9 @@
</role>
<organization>
<name>World Wide Web Consortium</name>
<address>
<formattedAddress>Address string</formattedAddress>
</address>
</organization>
</contributor>
<edition number="1.2">Edition 1</edition>
Expand Down
6 changes: 6 additions & 0 deletions spec/examples/hash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ contributor:
identifier:
- type: uri
id: www.ieee.org
contact:
- address:
formatted_address: Formatted address
role:
- description:
- content: Publisher description
Expand Down Expand Up @@ -203,6 +206,9 @@ contributor:
- organization:
name:
- content: World Wide Web Consortium
contact:
- address:
formatted_address: Address string
role:
- description:
- content: sponsor
Expand Down
16 changes: 12 additions & 4 deletions spec/relaton_bib/hash_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
expect(ls).to be_instance_of RelatonBib::LocalizedString
end

it "make localityStack form unwrapped loclaity" do
it "make localityStack from unwrapped loclaity" do
hash = { locality: [{ type: "section", reference_from: "1" }] }
RelatonBib::HashConverter.relation_locality_hash_to_bib hash
expect(hash[:locality].first).to be_instance_of RelatonBib::LocalityStack
end

it "make sourceLocalityStack form unwrapped sourceLoclaity" do
it "make sourceLocalityStack from unwrapped sourceLoclaity" do
hash = { source_locality: [{ type: "section", reference_from: "1" }] }
RelatonBib::HashConverter.relation_source_locality_hash_to_bib hash
expect(hash[:source_locality].first).to be_instance_of(
Expand All @@ -53,7 +53,7 @@
end

context "contacts_hash_to_bib" do
it "create address form old hash" do
it "create address from old hash" do
hash = { contact: [{ street: "Street", city: "City", country: "Country" }] }
address = described_class.contacts_hash_to_bib hash
expect(address).to be_instance_of Array
Expand All @@ -71,7 +71,15 @@
expect(address.first.formatted_address).to eq "Address"
end

it "create contact form old hash" do
it "create formatted address from string" do
entity = { contact: [{ address: "Address" }] }
address = RelatonBib::HashConverter.contacts_hash_to_bib entity
expect(address).to be_instance_of Array
expect(address.first).to be_instance_of RelatonBib::Address
expect(address.first.formatted_address).to eq "Address"
end

it "create contact from old hash" do
hash = { contact: [{ type: "phone", value: "123" }] }
contact = described_class.contacts_hash_to_bib hash
expect(contact).to be_instance_of Array
Expand Down

0 comments on commit b18bb64

Please sign in to comment.