Class: RelatonItu::Pubid
- Inherits:
-
Object
- Object
- RelatonItu::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:, sector:, 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:, sector:, code:, **args) ⇒ Pubid
Create a new ITU publication identifier.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/relaton_itu/pubid.rb', line 62 def initialize(prefix:, sector:, code:, **args) @prefix = prefix @sector = 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.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def amd @amd end |
#amd_date ⇒ Object
Returns the value of attribute amd_date.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def amd_date @amd_date end |
#annex ⇒ Object
Returns the value of attribute annex.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def annex @annex end |
#code ⇒ Object
Returns the value of attribute code.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def code @code end |
#day ⇒ Object
Returns the value of attribute day.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def day @day end |
#month ⇒ Object
Returns the value of attribute month.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def month @month end |
#prefix ⇒ Object
Returns the value of attribute prefix.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def prefix @prefix end |
#sector ⇒ Object
Returns the value of attribute sector.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def sector @sector end |
#suppl ⇒ Object
Returns the value of attribute suppl.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def suppl @suppl end |
#type ⇒ Object
Returns the value of attribute type.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def type @type end |
#version ⇒ Object
Returns the value of attribute version.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def version @version end |
#year ⇒ Object
Returns the value of attribute year.
45 46 47 |
# File 'lib/relaton_itu/pubid.rb', line 45 def year @year end |
Class Method Details
.parse(id) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/relaton_itu/pubid.rb', line 77 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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/relaton_itu/pubid.rb', line 117 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
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/relaton_itu/pubid.rb', line 86 def to_h(with_type: true) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity hash = { prefix: prefix, sector: sector, code: code } 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
100 101 102 |
# File 'lib/relaton_itu/pubid.rb', line 100 def to_ref to_s ref: true end |
#to_s(ref: false) ⇒ Object
rubocop:disable Metrics/AbcSize
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/relaton_itu/pubid.rb', line 104 def to_s(ref: false) # rubocop:disable Metrics/AbcSize s = "#{prefix}-#{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 |