Class: Pubid::Iso::Identifier

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, supplement: nil, joint_document: nil, urn_stage: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil, scnumber: nil, wgnumber: nil, dir: nil, dirtype: nil, year: nil, amendments: nil, corrigendums: nil, type: nil, **opts) ⇒ Identifier

Creates new identifier from options provided, includes options from Pubid::Core::Identifier#initialize

Parameters:

  • stage (Stage, Symbol, String) (defaults to: nil)

    stage, e.g. “PWI”, “NP”, “50.00”, Stage.new(abbr: :WD)

  • urn_stage (Float) (defaults to: nil)

    numeric stage for URN rendering

  • iteration (Integer) (defaults to: nil)

    document iteration, eg. “1”, “2”, “3”

  • joint_document (Identifier) (defaults to: nil)

    joint document

  • supplement (Supplement) (defaults to: nil)

    supplement

  • tctype (String) (defaults to: nil)

    Technical Committee type, eg. “TC”, “JTC”

  • sctype (String) (defaults to: nil)

    TC subsommittee, eg. “SC”

  • wgtype (String) (defaults to: nil)

    TC working group type, eg. “AG”, “AHG”

  • tcnumber (Integer) (defaults to: nil)

    Technical Committee number, eg. “1”, “2”

  • scnumber (Integer) (defaults to: nil)

    Subsommittee number, eg. “1”, “2”

  • wgnumber (Integer) (defaults to: nil)

    Working group number, eg. “1”, “2”

  • dirtype (String) (defaults to: nil)

    Directives document type, eg. “JTC”

Raises:

See Also:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/pubid/iso/identifier.rb', line 34

def initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, supplement: nil,
               joint_document: nil, urn_stage: nil,
               tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
               scnumber: nil, wgnumber:nil,
               dir: nil, dirtype: nil, year: nil, amendments: nil,
               corrigendums: nil, type: nil, **opts)
  super(**opts.merge(number: number, publisher: publisher, year: year,
                     amendments: amendments, corrigendums: corrigendums, type: type))

  if (amendments || corrigendums) && (year.nil? && stage.nil?)
    raise Errors::SupplementWithoutYearOrStageError, "Cannot apply supplement to document without edition year or stage"
  end
  if stage
    @stage = stage.is_a?(Stage) ? stage : Stage.parse(stage)

    if @stage.abbr == "IS" && iteration
      raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
    end

    if @stage.abbr == "FDIS" && type == "PAS"
      raise Errors::StageInvalidError, "PAS type cannot have FDIS stage"
    end
  end
  @iteration = iteration.to_i if iteration
  @supplement = supplement if supplement
  @joint_document = joint_document if joint_document
  @urn_stage = urn_stage if urn_stage
  @tctype = tctype if tctype
  @sctype = sctype.to_s if sctype
  @wgtype = wgtype.to_s if wgtype
  @tcnumber = tcnumber.to_s if tcnumber
  @scnumber = scnumber.to_s if scnumber
  @wgnumber = wgnumber.to_s if wgnumber
  @dir = dir.to_s if dir
  @dirtype = dirtype.to_s if dirtype
end

Instance Attribute Details

#dirtypeObject

Returns the value of attribute dirtype.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def dirtype
  @dirtype
end

#iterationObject

Returns the value of attribute iteration.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def iteration
  @iteration
end

#joint_documentObject

Returns the value of attribute joint_document.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def joint_document
  @joint_document
end

#scnumberObject

Returns the value of attribute scnumber.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def scnumber
  @scnumber
end

#sctypeObject

Returns the value of attribute sctype.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def sctype
  @sctype
end

#stageObject

Returns the value of attribute stage.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def stage
  @stage
end

#supplementObject

Returns the value of attribute supplement.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def supplement
  @supplement
end

#tcnumberObject

Returns the value of attribute tcnumber.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def tcnumber
  @tcnumber
end

#tctypeObject

Returns the value of attribute tctype.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def tctype
  @tctype
end

#urn_stageObject

Returns the value of attribute urn_stage.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def urn_stage
  @urn_stage
end

#wgnumberObject

Returns the value of attribute wgnumber.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def wgnumber
  @wgnumber
end

#wgtypeObject

Returns the value of attribute wgtype.



3
4
5
# File 'lib/pubid/iso/identifier.rb', line 3

def wgtype
  @wgtype
end

Class Method Details

.get_amendment_classObject



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

def get_amendment_class
  Pubid::Iso::Amendment
end

.get_corrigendum_classObject



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

def get_corrigendum_class
  Pubid::Iso::Corrigendum
end

.get_parser_classObject



89
90
91
# File 'lib/pubid/iso/identifier.rb', line 89

def get_parser_class
  Parser
end

.get_renderer_classObject



97
98
99
# File 'lib/pubid/iso/identifier.rb', line 97

def get_renderer_class
  Renderer::Base
end

.get_transformer_classObject



93
94
95
# File 'lib/pubid/iso/identifier.rb', line 93

def get_transformer_class
  Transformer
end

.parse_from_title(title) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/pubid/iso/identifier.rb', line 71

def self.parse_from_title(title)
  title.split.reverse.inject(title) do |acc, part|
    return parse(acc)
  rescue Pubid::Core::Errors::ParseError
    # delete parts from the title until it's parseable
    acc.reverse.sub(part.reverse, "").reverse.strip
  end
end

Instance Method Details

#to_s(lang: nil, with_date: true, with_edition: false, with_prf: false, format: :ref_dated_long) ⇒ String

Renders pubid identifier

Format options are:

:ref_num_short -- instance reference number: 1 letter language code + short form (DAM) + dated
:ref_num_long -- instance reference number long: 2 letter language code + long form (DAmd) + dated
:ref_dated -- reference dated: no language code + short form (DAM) + dated
:ref_dated_long -- reference dated long: no language code + short form (DAM) + dated
:ref_undated -- reference undated: no language code + short form (DAM) + undated
:ref_undated_long -- reference undated long: 1 letter language code + long form (DAmd) + undated

Parameters:

  • lang (:french, :russian) (defaults to: nil)

    use language specific renderer

  • with_date (Boolean) (defaults to: true)

    render identifier with date

  • with_edition (Boolean) (defaults to: false)

    render identifier with edition

  • stage_format_long (Boolean)

    render with long or short stage format

  • format (:ref_num_short, :ref_num_long, :ref_dated, :ref_dated_long, :ref_undated, :ref_undated_long) (defaults to: :ref_dated_long)

    create reference with specified format

Returns:

  • (String)

    pubid identifier



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/pubid/iso/identifier.rb', line 126

def to_s(lang: nil, with_date: true,
         with_edition: false, with_prf: false,
         format: :ref_dated_long)
  with_language_code = nil
  stage_format_long = nil
  if format
    case format
    when :ref_num_short
      with_language_code = :single
      stage_format_long = false
    when :ref_num_long
      with_language_code = :iso
      stage_format_long = true
    when :ref_dated
      with_language_code = :none
      stage_format_long = false
    when :ref_dated_long
      with_language_code = :none
      stage_format_long = true
    when :ref_undated
      with_language_code = :none
      stage_format_long = false
      with_date = false
    when :ref_undated_long
      with_language_code = :none
      stage_format_long = true
      with_date = false
    else
      raise Errors::WrongFormat, "#{format} is not available"
    end
  end
  case lang
  when :french
    Renderer::French.new(get_params)
  when :russian
    Renderer::Russian.new(get_params)
  else
    if @tctype
      Renderer::Tc.new(get_params)
    elsif @type == "DIR"
      Renderer::Dir.new(get_params)
    else
      self.class.get_renderer_class.new(get_params)
    end
  end.render(with_date: with_date, with_language_code: with_language_code, with_edition: with_edition,
             stage_format_long: stage_format_long, with_prf: with_prf) +
    if @joint_document && @type != "DIR"
      "|#{@joint_document}"
    end.to_s
end

#urnString

Render URN identifier

Returns:

  • (String)

    URN identifier



104
105
106
107
108
109
# File 'lib/pubid/iso/identifier.rb', line 104

def urn
  if (@amendments || @corrigendums) && !@edition
    raise Errors::NoEditionError, "Base document must have edition"
  end
  (@tctype && Renderer::UrnTc || @type == "DIR" && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
end