Class: Pubid::Iso::Identifier
- Inherits:
-
Object
- Object
- Pubid::Iso::Identifier
- Defined in:
- lib/pubid/iso/identifier.rb
Constant Summary collapse
- LANGUAGES =
{ "ru" => "R", "fr" => "F", "en" => "E", "ar" => "A", }.freeze
Instance Attribute Summary collapse
-
#amendment ⇒ Object
Returns the value of attribute amendment.
-
#amendment_number ⇒ Object
Returns the value of attribute amendment_number.
-
#amendment_stage ⇒ Object
Returns the value of attribute amendment_stage.
-
#amendment_version ⇒ Object
Returns the value of attribute amendment_version.
-
#copublisher ⇒ Object
Returns the value of attribute copublisher.
-
#corrigendum ⇒ Object
Returns the value of attribute corrigendum.
-
#corrigendum_number ⇒ Object
Returns the value of attribute corrigendum_number.
-
#corrigendum_stage ⇒ Object
Returns the value of attribute corrigendum_stage.
-
#corrigendum_version ⇒ Object
Returns the value of attribute corrigendum_version.
-
#edition ⇒ Object
Returns the value of attribute edition.
-
#iteration ⇒ Object
Returns the value of attribute iteration.
-
#joint_document ⇒ Object
Returns the value of attribute joint_document.
-
#language(with_language_code = :iso) ⇒ Object
Returns the value of attribute language.
-
#number ⇒ Object
Returns the value of attribute number.
-
#part ⇒ Object
Returns the value of attribute part.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
-
#scnumber ⇒ Object
Returns the value of attribute scnumber.
-
#sctype ⇒ Object
TC 184/SC/WG 4 - no wg number TC 184/SC 4/WG 12 - separate sc and wg number.
-
#stage ⇒ Object
Returns the value of attribute stage.
-
#substage ⇒ Object
Returns the value of attribute substage.
-
#supplements ⇒ Object
Returns the value of attribute supplements.
-
#tcnumber ⇒ Object
Returns the value of attribute tcnumber.
-
#tctype ⇒ Object
Returns the value of attribute tctype.
-
#type ⇒ Object
Returns the value of attribute type.
-
#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.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
Instance Method Summary collapse
- #get_params ⇒ Object
- #identifier(with_date, with_language_code) ⇒ Object
-
#initialize(**opts) ⇒ Identifier
constructor
A new instance of Identifier.
- #originator ⇒ Object
- #rendered_year ⇒ Object
- #to_s(lang: nil, with_date: true, with_language_code: :iso) ⇒ Object
- #urn ⇒ Object
Constructor Details
#initialize(**opts) ⇒ Identifier
Returns a new instance of Identifier.
18 19 20 |
# File 'lib/pubid/iso/identifier.rb', line 18 def initialize(**opts) opts.each { |key, value| send("#{key}=", value.is_a?(Array) && value || value.to_s) } end |
Instance Attribute Details
#amendment ⇒ Object
Returns the value of attribute amendment.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def amendment @amendment end |
#amendment_number ⇒ Object
Returns the value of attribute amendment_number.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def amendment_number @amendment_number end |
#amendment_stage ⇒ Object
Returns the value of attribute amendment_stage.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def amendment_stage @amendment_stage end |
#amendment_version ⇒ Object
Returns the value of attribute amendment_version.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def amendment_version @amendment_version end |
#copublisher ⇒ Object
Returns the value of attribute copublisher.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def copublisher @copublisher end |
#corrigendum ⇒ Object
Returns the value of attribute corrigendum.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def corrigendum @corrigendum end |
#corrigendum_number ⇒ Object
Returns the value of attribute corrigendum_number.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def corrigendum_number @corrigendum_number end |
#corrigendum_stage ⇒ Object
Returns the value of attribute corrigendum_stage.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def corrigendum_stage @corrigendum_stage end |
#corrigendum_version ⇒ Object
Returns the value of attribute corrigendum_version.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def corrigendum_version @corrigendum_version end |
#edition ⇒ Object
Returns the value of attribute edition.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def edition @edition 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 |
#language(with_language_code = :iso) ⇒ Object
Returns the value of attribute language.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def language @language end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def number @number end |
#part ⇒ Object
Returns the value of attribute part.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def part @part end |
#publisher ⇒ Object
Returns the value of attribute publisher.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def publisher @publisher 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
TC 184/SC/WG 4 - no wg number TC 184/SC 4/WG 12 - separate sc and wg number
97 98 99 |
# File 'lib/pubid/iso/identifier.rb', line 97 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 |
#substage ⇒ Object
Returns the value of attribute substage.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def substage @substage end |
#supplements ⇒ Object
Returns the value of attribute supplements.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def supplements @supplements 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 |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def type @type 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 |
#year ⇒ Object
Returns the value of attribute year.
3 4 5 |
# File 'lib/pubid/iso/identifier.rb', line 3 def year @year end |
Class Method Details
.parse(code_or_params) ⇒ Object
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 |
# File 'lib/pubid/iso/identifier.rb', line 39 def self.parse(code_or_params) params = code_or_params.is_a?(String) ? Parser.new.parse(code_or_params) : code_or_params # Parslet returns an array when match any copublisher # otherwise it's hash if params.is_a?(Array) new( **( params.inject({}) do |r, i| result = r i.map {|k, v| Transformer.new.apply(k => v).to_a.first }.each do |k, v| result = result.merge(k => r.key?(k) ? [v, r[k]] : v) end result end ) ) else new(**params.map do |k, v| Transformer.new.apply(k => v).to_a.first end.to_h) end # merge values repeating keys into array (for copublishers) # params.to_h) rescue Parslet::ParseFailed => failure raise Pubid::Iso::Errors::ParseError, "#{failure.}\ncause: #{failure.parse_failure_cause.ascii_tree}" end |
.parse_from_title(title) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/pubid/iso/identifier.rb', line 30 def self.parse_from_title(title) title.split.reverse.inject(title) do |acc, part| return parse(acc) rescue Pubid::Iso::Errors::ParseError # delete parts from the title until it's parseable acc.reverse.sub(part.reverse, "").reverse.strip end end |
Instance Method Details
#get_params ⇒ Object
22 23 24 |
# File 'lib/pubid/iso/identifier.rb', line 22 def get_params instance_variables.map { |var| [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)] }.to_h end |
#identifier(with_date, with_language_code) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/pubid/iso/identifier.rb', line 80 def identifier(with_date, with_language_code) if @tctype "#{originator} #{tctype} #{tcnumber}#{sctype}#{wgtype} N#{number}" else "#{originator}#{type}#{stage} #{number}#{part}#{iteration}"\ "#{with_date && rendered_year || ''}#{edition}#{supplements}#{language(with_language_code)}" end end |
#originator ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/pubid/iso/identifier.rb', line 123 def originator if copublisher # @copublisher = [@copublisher] unless @copublisher.is_a?(Array) # @copublisher.map! { |copublisher| copublisher.sub("IEC", "CEI") } if @french publisher + copublisher.map(&:to_s).sort.map do |copublisher| "/#{copublisher.gsub('-', '/')}" end.join else publisher end end |
#rendered_year ⇒ Object
143 144 145 |
# File 'lib/pubid/iso/identifier.rb', line 143 def rendered_year @year && ":#{@year}" end |
#to_s(lang: nil, with_date: true, with_language_code: :iso) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pubid/iso/identifier.rb', line 68 def to_s(lang: nil, with_date: true, with_language_code: :iso) # @pubid_language = lang case lang when :french French.new(**get_params) when :russian Russian.new(**get_params) else self end.identifier(with_date, with_language_code) + (@joint_document && "|#{@joint_document}").to_s end |