Class: Pubid::Bsi::Identifier::Base

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • month (Integer) (defaults to: nil)

    document’s month

  • edition (String) (defaults to: nil)

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



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

#adoptedObject

Returns the value of attribute adopted.



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

def adopted
  @adopted
end

#monthObject

Returns the value of attribute month.



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

def month
  @month
end

#pdfObject

Returns the value of attribute pdf.



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

def pdf
  @pdf
end

#supplementObject

Returns the value of attribute supplement.



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

def supplement
  @supplement
end

#tracked_changesObject

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

#translationObject

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_classObject



60
61
62
# File 'lib/pubid/bsi/identifier/base.rb', line 60

def get_parser_class
  Parser
end

.get_renderer_classObject



64
65
66
# File 'lib/pubid/bsi/identifier/base.rb', line 64

def get_renderer_class
  Renderer::Base
end

.get_transformer_classObject



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