metanorma / pubid-core

BSD 2-Clause "Simplified" License
1 stars 0 forks source link

#to_h doesn't render document type #34

Closed andrew2net closed 10 months ago

andrew2net commented 10 months ago

We need to recreate pubid from hash it produces, but the output hash misses document type:

> Pubid::Iso::Identifier.parse("ISO/TR 11071-2:1996").to_h
{:publisher=>"ISO", :number=>"11071"@7, :year=>1996, :part=>"2"@13, :edition=>nil}

And attributes with nil values shouldn't be in the output. We need something like this:

> pubid = Pubid::Iso::Identifier.parse("ISO/TR 11071-2:1996")
#<Pubid::Iso::Identifier::TechnicalReport:0x00000001011f3c20 @edition=nil, @number="11071"@7, @part="2"@13, @publisher="ISO", @year=1996>

> hash = pubid.to_h
{:publisher=>"ISO", :type=>"TR", :number=>"11071"@7, :year=>1996, :part=>"2"@13}

> Pubid::Iso::Identifier.new(**hash) == pubid
true