Class: Pubid::Cen::Identifier::Base

Inherits:
Pubid::Core::Identifier::Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pubid/cen/identifier/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number: nil, publisher: "EN", part: nil, stage: nil, incorporated_supplements: nil, adopted: nil, **opts) ⇒ Base

Returns a new instance of Base.

Parameters:

  • month (Integer)

    document’s month

  • edition (String)

    document’s edition version, e.g. “3.0”, “1.0”



15
16
17
18
19
20
21
22
# File 'lib/pubid/cen/identifier/base.rb', line 15

def initialize(number: nil, publisher: "EN", part: nil, stage: nil,
               incorporated_supplements: nil, adopted: nil, **opts)
  super(**opts.merge(publisher: publisher, number: number))
  @part = part if part
  @stage = Identifier.parse_stage(stage) if stage
  @supplements = incorporated_supplements
  @adopted = adopted
end

Instance Attribute Details

#adoptedObject

Returns the value of attribute adopted.



7
8
9
# File 'lib/pubid/cen/identifier/base.rb', line 7

def adopted
  @adopted
end

#supplementsObject

Returns the value of attribute supplements.



7
8
9
# File 'lib/pubid/cen/identifier/base.rb', line 7

def supplements
  @supplements
end

Class Method Details

.get_parser_classObject



47
48
49
# File 'lib/pubid/cen/identifier/base.rb', line 47

def get_parser_class
  Parser
end

.get_renderer_classObject



51
52
53
# File 'lib/pubid/cen/identifier/base.rb', line 51

def get_renderer_class
  Renderer::Base
end

.get_transformer_classObject



55
56
57
# File 'lib/pubid/cen/identifier/base.rb', line 55

def get_transformer_class
  Transformer
end

.transform(params) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pubid/cen/identifier/base.rb', line 25

def transform(params)
  identifier_params = params.map do |k, v|
    get_transformer_class.new.apply(k => v)
  end.inject({}, :merge)

  if identifier_params[:supplement]
    return transform_supplement(
      identifier_params[:supplement],
      identifier_params.dup.tap { |h| h.delete(:supplement) }
    )
  end

  Identifier.create(**identifier_params)
end

.transform_supplement(supplement_params, base_params) ⇒ Object



40
41
42
43
44
45
# File 'lib/pubid/cen/identifier/base.rb', line 40

def transform_supplement(supplement_params, base_params)
  Identifier.create(number: supplement_params[:number],
                    year: supplement_params[:year],
                    type: supplement_params[:type],
                    base: Identifier.create(**base_params))
end

.typeObject



9
10
11
# File 'lib/pubid/cen/identifier/base.rb', line 9

def self.type
  { key: :en, title: "European Norm" }
end