metanorma / pubid-iso

Implementation of ISO pubid
BSD 2-Clause "Simplified" License
1 stars 0 forks source link

URGENT! Fails to compare Amendments #255

Closed andrew2net closed 7 months ago

andrew2net commented 7 months ago

When one Pubid is created from Hash and another is parsed from String they aren't equal:


hash = {:number=>"1", :year=>"2011", :base=>{:publisher=>"ISO", :number=>"19110", :year=>"2005", :edition=>"1"}, :type=>"AMD"}

id1 = Pubid::Iso::Identifier.create(**hash)
=> #<Pubid::Iso::Identifier::Amendment:0x000000011d27ca90 @base=#<Pubid::Iso::Identifier::InternationalStandard:0x000000011d27c950 @edition="1", @month=nil, @number="19110", @publisher...

id1.to_s
=> "ISO 19110:2005/Amd 1:2011"

id2 = Pubid::Iso::Identifier.parse("ISO 19110:2005/Amd 1:2011")
=> #<Pubid::Iso::Identifier::Amendment:0x000000011d274390 @base=#<Pubid::Iso::Identifier::InternationalStandard:0x000000011d2744d0 @edition=nil, @month=nil, @number="19110", @publisher...

id1 == id2
=> false
mico commented 7 months ago

@andrew2net hash you using for identifier creation have "edition" key which is not reflected in output and different from parsed identifier.

But another thing that parsed "Amendment" have default publisher "ISO" which makes it different from identifier made from hash even without edition. I'll fix that.

andrew2net commented 7 months ago

@mico I noticed when an ID is parsed from string the #to_h output has empty publisher:

Pubid::Iso::Identifier.parse("ISO 19110:2005/Amd 1:2011").to_h
 => {:publisher=>"", :number=>"1", :year=>2011, :base=>{:publisher=>"ISO", :number=>"19110", :year=>2005, :edition=>nil, :month=>nil, :type=>nil}, :edition=>nil, :month=>nil, :type=>"AMD"}

I clear out empty and nil values before save ID in index. But when ID recreated from the cleared Hash the publisher is not empty:


Pubid::Iso::Identifier.create(number: "1", year: 2011, base: { publisher: "ISO", number: "19110", year: 2005 }, type: "AMD").to_h
 => {:publisher=>"ISO", :number=>"1", :year=>2011, :base=>{:publisher=>"ISO", :number=>"19110", :year=>2005, :edition=>nil, :month=>nil, :type=>nil}, :edition=>nil, :month=>nil, :type=>"AMD"}