Class: Pubid::Bsi::Identifier::Base
- Inherits:
-
Core::Identifier::Base
- Object
- Core::Identifier::Base
- Pubid::Bsi::Identifier::Base
- Extended by:
- Forwardable
- Defined in:
- lib/pubid/bsi/identifier/base.rb
Direct Known Subclasses
Amendment, BritishStandard, Collection, Corrigendum, DraftDocument, ExpertCommentary, Flex, NationalAnnex, PubliclyAvailableSpecification, PublishedDocument
Instance Attribute Summary collapse
-
#adopted ⇒ Object
Returns the value of attribute adopted.
-
#month ⇒ Object
Returns the value of attribute month.
-
#pdf ⇒ Object
Returns the value of attribute pdf.
-
#supplement ⇒ Object
Returns the value of attribute supplement.
-
#tracked_changes ⇒ Object
Returns the value of attribute tracked_changes.
-
#translation ⇒ Object
Returns the value of attribute translation.
Class Method Summary collapse
- .get_parser_class ⇒ Object
- .get_renderer_class ⇒ Object
- .get_transformer_class ⇒ Object
-
.transform(params) ⇒ Object
Use Identifier#create to resolve identifier’s type class.
- .transform_collection(params) ⇒ Object
- .transform_expert_commentary(base_params) ⇒ Object
- .transform_hash(params) ⇒ Object
- .transform_national_annex(params, base_params) ⇒ Object
Instance Method Summary collapse
-
#initialize(publisher: "BS", month: nil, edition: nil, supplement: nil, number: nil, adopted: nil, expert_commentary: false, tracked_changes: false, translation: nil, pdf: false, **opts) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(publisher: "BS", month: nil, edition: nil, supplement: nil, number: nil, adopted: nil, expert_commentary: false, tracked_changes: false, translation: nil, pdf: false, **opts) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pubid/bsi/identifier/base.rb', line 12 def initialize(publisher: "BS", month: nil, edition: nil, supplement: nil, number: nil, adopted: nil, expert_commentary: false, tracked_changes: false, translation: nil, pdf: false, **opts) super(**opts.merge(publisher: publisher, number: number)) @month = month if month @edition = edition if edition @supplement = supplement @adopted = adopted @tracked_changes = tracked_changes @translation = translation @pdf = pdf end |
Instance Attribute Details
#adopted ⇒ Object
Returns the value of attribute adopted.
6 7 8 |
# File 'lib/pubid/bsi/identifier/base.rb', line 6 def adopted @adopted end |
#month ⇒ Object
Returns the value of attribute month.
6 7 8 |
# File 'lib/pubid/bsi/identifier/base.rb', line 6 def month @month end |
#pdf ⇒ Object
Returns the value of attribute pdf.
6 7 8 |
# File 'lib/pubid/bsi/identifier/base.rb', line 6 def pdf @pdf end |
#supplement ⇒ Object
Returns the value of attribute supplement.
6 7 8 |
# File 'lib/pubid/bsi/identifier/base.rb', line 6 def supplement @supplement end |
#tracked_changes ⇒ Object
Returns the value of attribute tracked_changes.
6 7 8 |
# File 'lib/pubid/bsi/identifier/base.rb', line 6 def tracked_changes @tracked_changes end |
#translation ⇒ Object
Returns the value of attribute translation.
6 7 8 |
# File 'lib/pubid/bsi/identifier/base.rb', line 6 def translation @translation end |
Class Method Details
.get_parser_class ⇒ Object
72 73 74 |
# File 'lib/pubid/bsi/identifier/base.rb', line 72 def get_parser_class Parser end |
.get_renderer_class ⇒ Object
76 77 78 |
# File 'lib/pubid/bsi/identifier/base.rb', line 76 def get_renderer_class Renderer::Base end |
.get_transformer_class ⇒ Object
80 81 82 |
# File 'lib/pubid/bsi/identifier/base.rb', line 80 def get_transformer_class Transformer end |
.transform(params) ⇒ Object
Use Identifier#create to resolve identifier’s type class
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pubid/bsi/identifier/base.rb', line 35 def transform(params) identifier_params = transform_hash(params) if identifier_params[:national_annex] return transform_national_annex( identifier_params[:national_annex], identifier_params.dup.tap { |h| h.delete(:national_annex) }) end return transform_expert_commentary(identifier_params) if identifier_params[:expert_commentary] return transform_collection(identifier_params) if identifier_params[:second_number] Identifier.create(**identifier_params) end |
.transform_collection(params) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/pubid/bsi/identifier/base.rb', line 51 def transform_collection(params) first_identifier_params = params.reject { |k, _| %i[second_number year supplement].include?(k) } second_identifier_params = first_identifier_params.dup second_identifier_params[:number] = params[:second_number] Collection.new(identifiers: [Identifier.create(**first_identifier_params), Identifier.create(**second_identifier_params)], **params.slice(:supplement, :year)) end |
.transform_expert_commentary(base_params) ⇒ Object
61 62 63 64 |
# File 'lib/pubid/bsi/identifier/base.rb', line 61 def transform_expert_commentary(base_params) Identifier.create(type: :ec, base: Identifier.create(**base_params)) end |
.transform_hash(params) ⇒ Object
28 29 30 31 32 |
# File 'lib/pubid/bsi/identifier/base.rb', line 28 def transform_hash(params) params.map do |k, v| get_transformer_class.new.apply(k => v.is_a?(Hash) ? transform_hash(v) : v) end.inject({}, :merge) end |
.transform_national_annex(params, base_params) ⇒ Object
66 67 68 69 70 |
# File 'lib/pubid/bsi/identifier/base.rb', line 66 def transform_national_annex(params, base_params) Identifier.create(type: params[:type], supplement: params[:supplement], base: Identifier.create(**base_params)) end |