metanorma / pubid-core

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

Add to_h method #22

Closed andrew2net closed 1 year ago

andrew2net commented 1 year ago

We store parts of ID in index file. We need to get these pars from pubid with method to_h and recreate PubID from the hash:

> hash = pubid.to_h
{
  code: "800-121",
  publisher: "NIST",
  revision: "2",
  serie: "NIST SP"
}

> Pubid::Nist::Identifier.new(**hash)
 @code="800-121",
 @publisher=#<Pubid::Nist::Publisher:0x0000000109b619d0 @publisher="NIST">,
 @revision="2",
 @serie=#<Pubid::Nist::Serie:0x0000000109b62150 @parsed=nil, @serie="NIST SP">,
 @supplement=nil,
 @update=nil>
mico commented 1 year ago

@andrew2net we already have a method doing the same: #get_params, but #to_h will better reflect purpose of the method, so I'm renaming it.

andrew2net commented 1 year ago

@mico we need to document all the Pubid methods. You can use https://yardoc.org so we automatically get docs like this https://www.rubydoc.info/gems/relaton-bib/1.16.2/RelatonBib/Affiliation

mico commented 1 year ago

When using "typed stages" with input like:

{ type: "tr", number: 1, publisher: "ISO", stage: :dtr }

#to_h returns:

{:number=>1, :publisher=>"ISO", :stage=>#<Pubid::Core::Stage:0x000000010a7e31b8 @config=#<Pubid::Core...>{:long=>"Technical Report", :short=>"TR"}}>, @stages=["40.00"]>>, :type=>"tr", :typed_stage=>"DTR"}

which cannot be used to rebuild identifier again because of typed_stage parameter that we don't accept for constructor, "typed stage" should be applied through stage parameter.

andrew2net commented 1 year ago

@mico can we create Pubid::Core::Stage#to_h method? We need to serialize Pbid as a Hash and store in YAML file. And we need to be able to recreate the Pubid from the Hash. If it's impossible to create the stage parameter in Pubid constructor, let's make Pubid#from_hash parser method.