Skip to content

Commit

Permalink
Rename #get_params to #to_h method
Browse files Browse the repository at this point in the history
  • Loading branch information
mico committed Oct 9, 2023
1 parent 5925f11 commit 63ce213
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/pubid/core/identifier/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def initialize(publisher:, number:, copublisher: nil, part: nil, type: nil,

# @return [String] Rendered URN identifier
def urn
Renderer::Urn.new(get_params).render
Renderer::Urn.new(to_h).render
end

def get_params
def to_h
instance_variables.map do |var|
# XXX: temporary hack to prepare typed_stage for rendering
# probably need to convert typed_stage to class, now we store
Expand All @@ -76,12 +76,12 @@ def get_params
end

def ==(other)
get_params == other.get_params
to_h == other.to_h
end

# Render identifier using default renderer
def to_s
self.class.get_renderer_class.new(get_params).render
self.class.get_renderer_class.new(to_h).render
end

def typed_stage_abbrev
Expand Down
4 changes: 2 additions & 2 deletions lib/pubid/core/renderer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def prerender_params(params, opts)
def render_supplement(supplement_params, **args)
base = if supplement_params[:base].type == :amd
# render inner amendment (cor -> amd -> base)
render_supplement(supplement_params[:base].get_params, **args)
render_supplement(supplement_params[:base].to_h, **args)
else
self.class.new(supplement_params[:base].get_params).render_base_identifier(
self.class.new(supplement_params[:base].to_h).render_base_identifier(
# always render year for identifiers with supplement
**args.merge({ with_date: true }),
)
Expand Down
8 changes: 8 additions & 0 deletions spec/pubid_core/identifier/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ def self.get_identifier
end
end
end

describe "#to_h" do
subject { TestIdentifier.create(**params).to_h }

let(:params) { { type: "tr", number: 1, publisher: "ISO" } }

it { expect(subject).to eq(params) }
end
end

class TR < Pubid::Core::Identifier::Base
Expand Down

0 comments on commit 63ce213

Please sign in to comment.