Class: Pubid::Jis::Identifier::Base
- Inherits:
-
Core::Identifier::Base
- Object
- Core::Identifier::Base
- Pubid::Jis::Identifier::Base
show all
- Extended by:
- Forwardable
- Defined in:
- lib/pubid/jis/identifier/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(publisher: "JIS", series: nil, part: nil, all_parts: false, **opts) ⇒ Base
Returns a new instance of Base.
15
16
17
18
19
20
|
# File 'lib/pubid/jis/identifier/base.rb', line 15
def initialize(publisher: "JIS", series: nil, part: nil, all_parts: false, **opts)
super(**opts.merge(publisher: publisher))
@series = series if series
@part = part if part
@all_parts = all_parts
end
|
Instance Attribute Details
#all_parts ⇒ Object
Returns the value of attribute all_parts.
6
7
8
|
# File 'lib/pubid/jis/identifier/base.rb', line 6
def all_parts
@all_parts
end
|
#series ⇒ Object
Returns the value of attribute series.
6
7
8
|
# File 'lib/pubid/jis/identifier/base.rb', line 6
def series
@series
end
|
Class Method Details
.get_parser_class ⇒ Object
82
83
84
|
# File 'lib/pubid/jis/identifier/base.rb', line 82
def get_parser_class
Parser
end
|
.get_renderer_class ⇒ Object
86
87
88
|
# File 'lib/pubid/jis/identifier/base.rb', line 86
def get_renderer_class
Renderer::Base
end
|
Use Identifier#create to resolve identifier’s type class
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/pubid/jis/identifier/base.rb', line 60
def transform(params)
identifier_params = params.map do |k, v|
get_transformer_class.new.apply(k => v)
end.inject({}, :merge)
if identifier_params[:supplements]
return transform_supplements(
identifier_params[:supplements],
identifier_params.dup.tap { |h| h.delete(:supplements) }
)
end
if identifier_params[:explanation]
return transform_explanation(
identifier_params[:explanation].is_a?(Hash) ? identifier_params[:explanation] : {},
identifier_params.dup.tap { |h| h.delete(:explanation) }
)
end
Identifier.create(**identifier_params)
end
|
55
56
57
|
# File 'lib/pubid/jis/identifier/base.rb', line 55
def transform_explanation(params, base_params)
Identifier.create(type: :explanation, base: Identifier.create(**base_params), **params)
end
|
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/pubid/jis/identifier/base.rb', line 44
def transform_supplements(supplements_params, base_params)
supplements = supplements_params.map do |supplement|
Identifier.create(number: supplement[:number], year: supplement[:year],
type: :amd, base: Identifier.create(**base_params))
end
return supplements.first if supplements.count == 1
raise Errors::SupplementParsingError, "more than one or none supplements provided"
end
|
.type ⇒ Object
9
10
11
|
# File 'lib/pubid/jis/identifier/base.rb', line 9
def self.type
{ key: :jis, title: "Japanese Industrial Standard" }
end
|
Instance Method Details
#==(other) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/pubid/jis/identifier/base.rb', line 26
def ==(other)
if all_parts? || other.all_parts?
return get_params.reject { |k, _| [:year, :part, :all_parts].include?(k) } ==
other.get_params.reject { |k, _| [:year, :part, :all_parts].include?(k) }
end
super
end
|
#all_parts? ⇒ Boolean
22
23
24
|
# File 'lib/pubid/jis/identifier/base.rb', line 22
def all_parts?
all_parts
end
|
#to_s(with_publisher: true) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/pubid/jis/identifier/base.rb', line 36
def to_s(with_publisher: true)
options = {}
options[:with_publisher] = with_publisher
self.class.get_renderer_class.new(get_params).render(**options)
end
|