Class: Pubid::Etsi::Identifier::Base

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

Direct Known Subclasses

Supplement

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, published:, publisher: "ETSI", version: nil, part: nil, **opts) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pubid/etsi/identifier/base.rb', line 14

def initialize(type:, published:, publisher: "ETSI", version: nil, part: nil, **opts)
  super(**opts.merge(publisher: publisher))
  @published = published
  @version = version
  @part = part
  if type
    unless Identifier.config.type_names.map { |_, v| v[:short] }.include?(type)
      raise Pubid::Core::Errors::WrongTypeError, "Type '#{type}' is not available"
    end
    @type = type
  end
end

Instance Attribute Details

#publishedObject

Returns the value of attribute published.



8
9
10
# File 'lib/pubid/etsi/identifier/base.rb', line 8

def published
  @published
end

#versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/pubid/etsi/identifier/base.rb', line 8

def version
  @version
end

Class Method Details

.get_parser_classObject



50
51
52
# File 'lib/pubid/etsi/identifier/base.rb', line 50

def get_parser_class
  Parser
end

.get_renderer_classObject



54
55
56
# File 'lib/pubid/etsi/identifier/base.rb', line 54

def get_renderer_class
  Renderer::Base
end

.transform(params) ⇒ Object

Use Identifier#create to resolve identifier’s type class



39
40
41
42
43
44
45
46
47
48
# File 'lib/pubid/etsi/identifier/base.rb', line 39

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

  %i(amendment corrigendum).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



28
29
30
31
32
33
34
35
36
# File 'lib/pubid/etsi/identifier/base.rb', line 28

def transform_supplements(type, identifier_params)
  Identifier.create(
    type: type,
    base: transform(
      **identifier_params.dup.tap { |h| h.delete(type) },
    ),
    **identifier_params[type],
  )
end

.typeObject



10
11
12
# File 'lib/pubid/etsi/identifier/base.rb', line 10

def self.type
  { key: :etsi }
end