Class: Relaton::Iec::Docidentifier

Inherits:
Bib::Docidentifier
  • Object
show all
Defined in:
lib/relaton/iec/model/docidentifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil, **kwargs) ⇒ Docidentifier

Returns a new instance of Docidentifier.



8
9
10
11
12
# File 'lib/relaton/iec/model/docidentifier.rb', line 8

def initialize(arg = nil, **kwargs)
  arg.is_a?(Hash) ? super(arg) : super(**kwargs)
  raw = arg.is_a?(Hash) ? (arg["content"] || arg[:content]) : kwargs[:content]
  self.content = raw if raw
end

Instance Attribute Details

#pubidObject (readonly)

Returns the value of attribute pubid.



6
7
8
# File 'lib/relaton/iec/model/docidentifier.rb', line 6

def pubid
  @pubid
end

Instance Method Details

#contentObject



42
43
44
45
46
47
# File 'lib/relaton/iec/model/docidentifier.rb', line 42

def content
  return @raw_content if @raw_content
  return render_pubid(@pubid) if @pubid

  original_content
end

#content=(value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/relaton/iec/model/docidentifier.rb', line 17

def content=(value)
  @pubid = nil
  @raw_content = nil

  parsed =
    case value
    when ::Pubid::Iec::Base then value
    when String
      begin
        ::Pubid::Iec::Identifier.parse(value)
      rescue StandardError
        Util.warn "Failed to parse Pubid: #{value}"
        nil
      end
    end

  if parsed
    @pubid = parsed
  elsif value.is_a?(String)
    @raw_content = value
  end

  send(:original_content=, to_s)
end

#original_contentObject



15
# File 'lib/relaton/iec/model/docidentifier.rb', line 15

alias_method :original_content, :content

#original_content=Object



14
# File 'lib/relaton/iec/model/docidentifier.rb', line 14

alias_method :original_content=, :content=

#remove_date!Object



71
72
73
# File 'lib/relaton/iec/model/docidentifier.rb', line 71

def remove_date!
  remove_attr!(:year)
end

#remove_part!Object



67
68
69
# File 'lib/relaton/iec/model/docidentifier.rb', line 67

def remove_part!
  remove_attr!(:part)
end

#remove_stage!Object



63
64
65
# File 'lib/relaton/iec/model/docidentifier.rb', line 63

def remove_stage!
  remove_attr!(:stage)
end

#to_all_parts!Object



53
54
55
56
57
58
59
60
61
# File 'lib/relaton/iec/model/docidentifier.rb', line 53

def to_all_parts!
  return unless @pubid

  remove_part!
  remove_date!
  remove_stage!
  @pubid.all_parts = true if @pubid.respond_to?(:all_parts=)
  refresh_content!
end

#to_sObject



49
50
51
# File 'lib/relaton/iec/model/docidentifier.rb', line 49

def to_s
  content.to_s
end