Class: Pubid::Itu::Identifier::Base

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(publisher: "ITU", series: nil, sector: nil, part: nil, date: nil, amendment: nil, subseries: nil, number: nil, second_number: nil, annex: nil, range: 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”



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pubid/itu/identifier/base.rb', line 17

def initialize(publisher: "ITU", series: nil, sector: nil, part: nil,
               date: nil, amendment: nil, subseries: nil, number: nil,
               second_number: nil, annex: nil, range: nil, **opts)

  super(**opts.merge(publisher: publisher, number: number))
  @series = series
  @sector = sector
  @part = part if part
  @date = date
  @amendment = amendment
  @subseries = subseries
  @second_number = second_number
  @annex = annex
  @range = range
end

Instance Attribute Details

#amendmentObject

Returns the value of attribute amendment.



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

def amendment
  @amendment
end

#annexObject

Returns the value of attribute annex.



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

def annex
  @annex
end

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#rangeObject

Returns the value of attribute range.



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

def range
  @range
end

#second_numberObject

Returns the value of attribute second_number.



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

def second_number
  @second_number
end

#sectorObject

Returns the value of attribute sector.



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

def sector
  @sector
end

#seriesObject

Returns the value of attribute series.



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

def series
  @series
end

#subseriesObject

Returns the value of attribute subseries.



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

def subseries
  @subseries
end

Class Method Details

.get_parser_classObject



77
78
79
# File 'lib/pubid/itu/identifier/base.rb', line 77

def get_parser_class
  Parser
end

.get_renderer_classObject



81
82
83
# File 'lib/pubid/itu/identifier/base.rb', line 81

def get_renderer_class
  Renderer::Base
end

.get_transformer_classObject



85
86
87
# File 'lib/pubid/itu/identifier/base.rb', line 85

def get_transformer_class
  Transformer
end

.has_type?(type) ⇒ Boolean

returns true when type matching current class type

Returns:

  • (Boolean)


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

def has_type?(type)
  return type == self.type[:key] if type.is_a?(Symbol)

  if self.type.key?(:short)
    self.type[:short].is_a?(Array) ? self.type[:short].include?(type) : self.type[:short] == type
  else
    type.to_s.downcase.to_sym == self.type[:key]
  end
end

.transform(params) ⇒ Object

Use Identifier#create to resolve identifier’s type class



66
67
68
69
70
71
72
73
74
75
# File 'lib/pubid/itu/identifier/base.rb', line 66

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

  %i(supplement amendment corrigendum annex addendum appendix).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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pubid/itu/identifier/base.rb', line 49

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

.typeObject



11
12
13
# File 'lib/pubid/itu/identifier/base.rb', line 11

def self.type
  { key: :itu, title: "International Communication Union" }
end

Instance Method Details

#to_s(**opts) ⇒ Object



33
34
35
# File 'lib/pubid/itu/identifier/base.rb', line 33

def to_s(**opts)
  self.class.get_renderer_class.new(to_h(deep: false)).render(**opts)
end