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.
-
#annex ⇒ Object
Returns the value of attribute annex.
-
#code ⇒ Object
Returns the value of attribute code.
-
#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.
-
#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.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/relaton_itu/pubid.rb', line 52 def initialize(prefix:, sector:, code:, **args) @prefix = prefix @sector = sector @type = args[:type] @code, year, month = date_from_code code @suppl = args[:suppl] @annex = args[:annex] @year = args[:year] || year @month = roman_to_2digit args[:month] || month @amd = args[:amd] end |
Instance Attribute Details
#amd ⇒ Object
Returns the value of attribute amd.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def amd @amd end |
#annex ⇒ Object
Returns the value of attribute annex.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def annex @annex end |
#code ⇒ Object
Returns the value of attribute code.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def code @code end |
#month ⇒ Object
Returns the value of attribute month.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def month @month end |
#prefix ⇒ Object
Returns the value of attribute prefix.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def prefix @prefix end |
#sector ⇒ Object
Returns the value of attribute sector.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def sector @sector end |
#suppl ⇒ Object
Returns the value of attribute suppl.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def suppl @suppl end |
#type ⇒ Object
Returns the value of attribute type.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def type @type end |
#year ⇒ Object
Returns the value of attribute year.
38 39 40 |
# File 'lib/relaton_itu/pubid.rb', line 38 def year @year end |
Class Method Details
.parse(id) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/relaton_itu/pubid.rb', line 64 def self.parse(id) id_parts = Parser.new.parse(id).to_h.transform_values(&:to_s) new(**id_parts) rescue Parslet::ParseFailed => e Util.warn "WARNING: `#{id}` is invalid ITU publication identifier \n" \ "#{e.parse_failure_cause.ascii_tree}" raise e end |
Instance Method Details
#===(other, ignore_args = []) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/relaton_itu/pubid.rb', line 99 def ===(other, ignore_args = []) hash = to_h with_type: false other_hash = other.to_h with_type: false hash.delete(:month) other_hash.delete(:month) hash.delete(:year) if ignore_args.include?(:year) other_hash.delete(:year) unless hash[:year] hash == other_hash end |
#to_h(with_type: true) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/relaton_itu/pubid.rb', line 73 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[:year] = year if year hash[:month] = month if month hash[:amd] = amd if amd hash end |
#to_ref ⇒ Object
84 85 86 |
# File 'lib/relaton_itu/pubid.rb', line 84 def to_ref to_s ref: true end |
#to_s(ref: false) ⇒ Object
rubocop:disable Metrics/AbcSize
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/relaton_itu/pubid.rb', line 88 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 << date_to_s s << " Amd #{amd}" if amd s end |