Class: Relaton::Itu::Pubid
- Inherits:
-
Object
- Object
- Relaton::Itu::Pubid
- Defined in:
- lib/relaton/itu/pubid.rb
Defined Under Namespace
Classes: Parser
Instance Attribute Summary collapse
-
#amd ⇒ Object
Returns the value of attribute amd.
-
#amd_date ⇒ Object
Returns the value of attribute amd_date.
-
#annex ⇒ Object
Returns the value of attribute annex.
-
#code ⇒ Object
Returns the value of attribute code.
-
#day ⇒ Object
Returns the value of attribute day.
-
#month ⇒ Object
Returns the value of attribute month.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#sector ⇒ Object
Returns the value of attribute sector.
-
#suppl ⇒ Object
Returns the value of attribute suppl.
-
#type ⇒ Object
Returns the value of attribute type.
-
#version ⇒ Object
Returns the value of attribute version.
-
#year ⇒ Object
Returns the value of attribute year.
Class Method Summary collapse
Instance Method Summary collapse
- #===(other, ignore_args = []) ⇒ Object
-
#initialize(prefix:, code:, **args) ⇒ Pubid
constructor
Create a new ITU publication identifier.
-
#to_h(with_type: true) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
- #to_ref ⇒ Object
-
#to_s(ref: false) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(prefix:, code:, **args) ⇒ Pubid
Create a new ITU publication identifier.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/relaton/itu/pubid.rb', line 56 def initialize(prefix:, code:, **args) @prefix = prefix @sector = args[:sector] @type = args[:type] @day = args[:day] @code, year, month = date_from_code code @suppl = args[:suppl] @annex = args[:annex] @version = args[:version] @year = args[:year] || year @month = roman_to_2digit args[:month] || month @amd = args[:amd] @amd_date = args[:amd_date] end |
Instance Attribute Details
#amd ⇒ Object
Returns the value of attribute amd.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def amd @amd end |
#amd_date ⇒ Object
Returns the value of attribute amd_date.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def amd_date @amd_date end |
#annex ⇒ Object
Returns the value of attribute annex.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def annex @annex end |
#code ⇒ Object
Returns the value of attribute code.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def code @code end |
#day ⇒ Object
Returns the value of attribute day.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def day @day end |
#month ⇒ Object
Returns the value of attribute month.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def month @month end |
#prefix ⇒ Object
Returns the value of attribute prefix.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def prefix @prefix end |
#sector ⇒ Object
Returns the value of attribute sector.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def sector @sector end |
#suppl ⇒ Object
Returns the value of attribute suppl.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def suppl @suppl end |
#type ⇒ Object
Returns the value of attribute type.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def type @type end |
#version ⇒ Object
Returns the value of attribute version.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def version @version end |
#year ⇒ Object
Returns the value of attribute year.
48 49 50 |
# File 'lib/relaton/itu/pubid.rb', line 48 def year @year end |
Class Method Details
.parse(id) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/relaton/itu/pubid.rb', line 71 def self.parse(id) id_parts = Parser.new.parse(id).to_h.transform_values(&:to_s) new(**id_parts) rescue Parslet::ParseFailed => e Util.error "`#{id}` is invalid ITU publication identifier\n" \ "#{e.parse_failure_cause.ascii_tree}" raise e end |
Instance Method Details
#===(other, ignore_args = []) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/relaton/itu/pubid.rb', line 113 def ===(other, ignore_args = []) hash = to_h with_type: false other_hash = other.to_h with_type: false hash.delete(:version) if ignore_args.include?(:version) other_hash.delete(:version) unless hash[:version] hash.delete(:day) other_hash.delete(:day) hash.delete(:month) other_hash.delete(:month) hash.delete(:year) if ignore_args.include?(:year) other_hash.delete(:year) unless hash[:year] hash.delete(:amd_date) if ignore_args.include?(:amd_date) other_hash.delete(:amd_date) unless hash[:amd_date] hash == other_hash end |
#to_h(with_type: true) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/relaton/itu/pubid.rb', line 80 def to_h(with_type: true) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity hash = { prefix: prefix, code: code } hash[:sector] = sector if sector hash[:type] = type if type && with_type hash[:suppl] = suppl if suppl hash[:annex] = annex if annex hash[:version] = version if version hash[:year] = year if year hash[:month] = month if month hash[:day] = day if day hash[:amd] = amd if amd hash[:amd_date] = amd_date if amd_date hash end |
#to_ref ⇒ Object
95 96 97 |
# File 'lib/relaton/itu/pubid.rb', line 95 def to_ref to_s ref: true end |
#to_s(ref: false) ⇒ Object
rubocop:disable Metrics/AbcSize
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/relaton/itu/pubid.rb', line 99 def to_s(ref: false) # rubocop:disable Metrics/AbcSize s = prefix.dup s << "-#{sector}" if sector s << " #{type}" if type && !ref s << " #{code}" s << " Suppl. #{suppl}" if suppl s << " Annex #{annex}" if annex s << " (V#{version})" if version s << date_to_s s << " Amd #{amd}" if amd s << " (#{amd_date})" if amd_date s end |