Class: Pubid::Iso::Identifier
- Inherits:
-
Core::Identifier
- Object
- Core::Identifier
- Pubid::Iso::Identifier
- Defined in:
- lib/pubid/iso/identifier.rb
Instance Attribute Summary collapse
-
#dirtype ⇒ Object
Returns the value of attribute dirtype.
-
#iteration ⇒ Object
Returns the value of attribute iteration.
-
#joint_document ⇒ Object
Returns the value of attribute joint_document.
-
#scnumber ⇒ Object
Returns the value of attribute scnumber.
-
#sctype ⇒ Object
Returns the value of attribute sctype.
-
#stage ⇒ Object
Returns the value of attribute stage.
-
#supplement ⇒ Object
Returns the value of attribute supplement.
-
#tcnumber ⇒ Object
Returns the value of attribute tcnumber.
-
#tctype ⇒ Object
Returns the value of attribute tctype.
-
#urn_stage ⇒ Object
Returns the value of attribute urn_stage.
-
#wgnumber ⇒ Object
Returns the value of attribute wgnumber.
-
#wgtype ⇒ Object
Returns the value of attribute wgtype.
Class Method Summary collapse
- .get_amendment_class ⇒ Object
- .get_corrigendum_class ⇒ Object
- .get_parser_class ⇒ Object
- .get_renderer_class ⇒ Object
- .get_transformer_class ⇒ Object
- .parse_from_title(title) ⇒ Object
Instance Method Summary collapse
-
#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
constructor
Creates new identifier from options provided, includes options from Pubid::Core::Identifier#initialize.
-
#to_s(lang: nil, with_date: true, with_edition: false, with_prf: false, format: :ref_dated_long) ⇒ String
Renders pubid identifier.
-
#urn ⇒ String
Render URN identifier.
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
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
#dirtype ⇒ Object
Returns the value of attribute dirtype.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def dirtype @dirtype end |
#iteration ⇒ Object
Returns the value of attribute iteration.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def iteration @iteration end |
#joint_document ⇒ Object
Returns the value of attribute joint_document.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def joint_document @joint_document end |
#scnumber ⇒ Object
Returns the value of attribute scnumber.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def scnumber @scnumber end |
#sctype ⇒ Object
Returns the value of attribute sctype.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def sctype @sctype end |
#stage ⇒ Object
Returns the value of attribute stage.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def stage @stage end |
#supplement ⇒ Object
Returns the value of attribute supplement.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def supplement @supplement end |
#tcnumber ⇒ Object
Returns the value of attribute tcnumber.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def tcnumber @tcnumber end |
#tctype ⇒ Object
Returns the value of attribute tctype.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def tctype @tctype end |
#urn_stage ⇒ Object
Returns the value of attribute urn_stage.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def urn_stage @urn_stage end |
#wgnumber ⇒ Object
Returns the value of attribute wgnumber.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def wgnumber @wgnumber end |
#wgtype ⇒ Object
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_class ⇒ Object
81 82 83 |
# File 'lib/pubid/iso/identifier.rb', line 81 def get_amendment_class Pubid::Iso::Amendment end |
.get_corrigendum_class ⇒ Object
85 86 87 |
# File 'lib/pubid/iso/identifier.rb', line 85 def get_corrigendum_class Pubid::Iso::Corrigendum end |
.get_parser_class ⇒ Object
89 90 91 |
# File 'lib/pubid/iso/identifier.rb', line 89 def get_parser_class Parser end |
.get_renderer_class ⇒ Object
97 98 99 |
# File 'lib/pubid/iso/identifier.rb', line 97 def get_renderer_class Renderer::Base end |
.get_transformer_class ⇒ Object
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
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 |
#urn ⇒ String
Render 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 |