Class: Pubid::Iho::Identifier::Base

Inherits:
Core::Identifier::Base
  • Object
show all
Defined in:
lib/pubid/iho/identifier/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pubid/iho/identifier/base.rb', line 10

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

Instance Attribute Details

#appendixObject

Returns the value of attribute appendix.



4
5
6
# File 'lib/pubid/iho/identifier/base.rb', line 4

def appendix
  @appendix
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/pubid/iho/identifier/base.rb', line 4

def version
  @version
end

Class Method Details

.get_parser_classObject



32
33
34
# File 'lib/pubid/iho/identifier/base.rb', line 32

def get_parser_class
  Parser
end

.get_renderer_classObject



36
37
38
# File 'lib/pubid/iho/identifier/base.rb', line 36

def get_renderer_class
  Renderer::Base
end

.transform(params) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/pubid/iho/identifier/base.rb', line 24

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

  Identifier.create(**identifier_params)
end

.typeObject



6
7
8
# File 'lib/pubid/iho/identifier/base.rb', line 6

def self.type
  { key: :iho }
end