Class: Pubid::Itu::Identifier::Base
- Inherits:
-
Core::Identifier::Base
- Object
- Core::Identifier::Base
- Pubid::Itu::Identifier::Base
- Extended by:
- Forwardable
- Defined in:
- lib/pubid/itu/identifier/base.rb
Direct Known Subclasses
Contribution, ImplementersGuide, Question, Recommendation, RegulatoryPublication, Resolution, SpecialPublication, Supplement
Instance Attribute Summary collapse
-
#amendment ⇒ Object
Returns the value of attribute amendment.
-
#annex ⇒ Object
Returns the value of attribute annex.
-
#date ⇒ Object
Returns the value of attribute date.
-
#range ⇒ Object
Returns the value of attribute range.
-
#second_number ⇒ Object
Returns the value of attribute second_number.
-
#sector ⇒ Object
Returns the value of attribute sector.
-
#series ⇒ Object
Returns the value of attribute series.
-
#subseries ⇒ Object
Returns the value of attribute subseries.
Class Method Summary collapse
- .get_parser_class ⇒ Object
- .get_renderer_class ⇒ Object
- .get_transformer_class ⇒ Object
-
.has_type?(type) ⇒ Boolean
returns true when type matching current class type.
-
.transform(params) ⇒ Object
Use Identifier#create to resolve identifier’s type class.
- .transform_supplements(type, identifier_params) ⇒ Object
- .type ⇒ Object
Instance Method Summary collapse
-
#initialize(publisher: "ITU", series: nil, sector: nil, part: nil, date: nil, amendment: nil, subseries: nil, number: nil, second_number: nil, annex: nil, range: nil, **opts) ⇒ Base
constructor
A new instance of Base.
- #to_s(**opts) ⇒ Object
Constructor Details
#initialize(publisher: "ITU", series: nil, sector: nil, part: nil, date: nil, amendment: nil, subseries: nil, number: nil, second_number: nil, annex: nil, range: nil, **opts) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pubid/itu/identifier/base.rb', line 17 def initialize(publisher: "ITU", series: nil, sector: nil, part: nil, date: nil, amendment: nil, subseries: nil, number: nil, second_number: nil, annex: nil, range: nil, **opts) super(**opts.merge(publisher: publisher, number: number)) @series = series @sector = sector @part = part if part @date = date @amendment = amendment @subseries = subseries @second_number = second_number @annex = annex @range = range end |
Instance Attribute Details
#amendment ⇒ Object
Returns the value of attribute amendment.
6 7 8 |
# File 'lib/pubid/itu/identifier/base.rb', line 6 def amendment @amendment end |
#annex ⇒ Object
Returns the value of attribute annex.
6 7 8 |
# File 'lib/pubid/itu/identifier/base.rb', line 6 def annex @annex end |
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/pubid/itu/identifier/base.rb', line 6 def date @date end |
#range ⇒ Object
Returns the value of attribute range.
6 7 8 |
# File 'lib/pubid/itu/identifier/base.rb', line 6 def range @range end |
#second_number ⇒ Object
Returns the value of attribute second_number.
6 7 8 |
# File 'lib/pubid/itu/identifier/base.rb', line 6 def second_number @second_number end |
#sector ⇒ Object
Returns the value of attribute sector.
6 7 8 |
# File 'lib/pubid/itu/identifier/base.rb', line 6 def sector @sector end |
#series ⇒ Object
Returns the value of attribute series.
6 7 8 |
# File 'lib/pubid/itu/identifier/base.rb', line 6 def series @series end |
#subseries ⇒ Object
Returns the value of attribute subseries.
6 7 8 |
# File 'lib/pubid/itu/identifier/base.rb', line 6 def subseries @subseries end |
Class Method Details
.get_parser_class ⇒ Object
77 78 79 |
# File 'lib/pubid/itu/identifier/base.rb', line 77 def get_parser_class Parser end |
.get_renderer_class ⇒ Object
81 82 83 |
# File 'lib/pubid/itu/identifier/base.rb', line 81 def get_renderer_class Renderer::Base end |
.get_transformer_class ⇒ Object
85 86 87 |
# File 'lib/pubid/itu/identifier/base.rb', line 85 def get_transformer_class Transformer end |
.has_type?(type) ⇒ Boolean
returns true when type matching current class type
39 40 41 42 43 44 45 46 47 |
# File 'lib/pubid/itu/identifier/base.rb', line 39 def has_type?(type) return type == self.type[:key] if type.is_a?(Symbol) if self.type.key?(:short) self.type[:short].is_a?(Array) ? self.type[:short].include?(type) : self.type[:short] == type else type.to_s.downcase.to_sym == self.type[:key] end end |
.transform(params) ⇒ Object
Use Identifier#create to resolve identifier’s type class
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pubid/itu/identifier/base.rb', line 66 def transform(params) identifier_params = params.map do |k, v| get_transformer_class.new.apply(k => v) end.inject({}, :merge) %i(supplement amendment corrigendum annex addendum appendix).each do |type| return transform_supplements(type, identifier_params) if identifier_params[type] end Identifier.create(**identifier_params) end |
.transform_supplements(type, identifier_params) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/pubid/itu/identifier/base.rb', line 49 def transform_supplements(type, identifier_params) if identifier_params[type].is_a?(Hash) Identifier.create( type: type, base: transform( **identifier_params.dup.tap { |h| h.delete(type) }), **identifier_params[type], ) else Identifier.create( type: type, base: transform(**identifier_params.dup.tap { |h| h.delete(type) }) ) end end |
.type ⇒ Object
11 12 13 |
# File 'lib/pubid/itu/identifier/base.rb', line 11 def self.type { key: :itu, title: "International Communication Union" } end |
Instance Method Details
#to_s(**opts) ⇒ Object
33 34 35 |
# File 'lib/pubid/itu/identifier/base.rb', line 33 def to_s(**opts) self.class.get_renderer_class.new(to_h(deep: false)).render(**opts) end |