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, 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_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
60 61 62 |
# File 'lib/pubid/bsi/identifier/base.rb', line 60 def get_parser_class Parser end |
.get_renderer_class ⇒ Object
64 65 66 |
# File 'lib/pubid/bsi/identifier/base.rb', line 64 def get_renderer_class Renderer::Base end |
.get_transformer_class ⇒ Object
68 69 70 |
# File 'lib/pubid/bsi/identifier/base.rb', line 68 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 |
# 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] Identifier.create(**identifier_params) end |
.transform_expert_commentary(base_params) ⇒ Object
49 50 51 52 |
# File 'lib/pubid/bsi/identifier/base.rb', line 49 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
54 55 56 57 58 |
# File 'lib/pubid/bsi/identifier/base.rb', line 54 def transform_national_annex(params, base_params) Identifier.create(type: params[:type], supplement: params[:supplement], base: Identifier.create(**base_params)) end |