Class: Opencdd::IRDI
- Inherits:
-
Object
- Object
- Opencdd::IRDI
- Defined in:
- lib/opencdd/irdi.rb
Constant Summary collapse
- FULL_REGEX =
%r{ \A (?<registrant>[^/#\s]+) / (?<semantic>[^/#\s]*) /// (?<scheme>[^/#\s]+) \# (?<code>[^#\s]+) (?:\#\#(?<smver>\d+))? \z }x- SHORT_REGEX =
/\A[^#\/\s]+\z/- TREE_REGEX =
%r{ \A (?<registrant>[^-]+) - (?<semantic>[^-]*) --- (?<scheme>[^-]+) %23 (?<code>[^%\s]+) \z }x
Instance Attribute Summary collapse
-
#code ⇒ Object
(also: #short)
readonly
Returns the value of attribute code.
-
#registrant ⇒ Object
readonly
Returns the value of attribute registrant.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#semantic ⇒ Object
readonly
Returns the value of attribute semantic.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #full? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(registrant:, semantic:, scheme:, code:, version: nil) ⇒ IRDI
constructor
A new instance of IRDI.
- #inspect ⇒ Object
- #sheetmap_version ⇒ Object
- #short? ⇒ Boolean
- #to_s ⇒ Object (also: #to_str)
- #to_tree_path ⇒ Object
- #with_code(new_code) ⇒ Object
Constructor Details
#initialize(registrant:, semantic:, scheme:, code:, version: nil) ⇒ IRDI
Returns a new instance of IRDI.
62 63 64 65 66 67 68 69 |
# File 'lib/opencdd/irdi.rb', line 62 def initialize(registrant:, semantic:, scheme:, code:, version: nil) @registrant = registrant&.to_s @semantic = semantic&.to_s @scheme = scheme&.to_s @code = code.to_s @version = version&.to_s freeze end |
Instance Attribute Details
#code ⇒ Object (readonly) Also known as: short
Returns the value of attribute code.
32 33 34 |
# File 'lib/opencdd/irdi.rb', line 32 def code @code end |
#registrant ⇒ Object (readonly)
Returns the value of attribute registrant.
32 33 34 |
# File 'lib/opencdd/irdi.rb', line 32 def registrant @registrant end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
32 33 34 |
# File 'lib/opencdd/irdi.rb', line 32 def scheme @scheme end |
#semantic ⇒ Object (readonly)
Returns the value of attribute semantic.
32 33 34 |
# File 'lib/opencdd/irdi.rb', line 32 def semantic @semantic end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
32 33 34 |
# File 'lib/opencdd/irdi.rb', line 32 def version @version end |
Class Method Details
.coerce(value) ⇒ Object
123 124 125 126 |
# File 'lib/opencdd/irdi.rb', line 123 def self.coerce(value) return value if value.is_a?(Opencdd::IRDI) parse(value) end |
.from_match(m) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opencdd/irdi.rb', line 51 def self.from_match(m) caps = m.named_captures.transform_keys(&:to_sym) new( registrant: caps[:registrant], semantic: caps[:semantic], scheme: caps[:scheme], code: caps[:code], version: caps[:smver], ) end |
.from_short(code) ⇒ Object
47 48 49 |
# File 'lib/opencdd/irdi.rb', line 47 def self.from_short(code) new(registrant: nil, semantic: nil, scheme: nil, code: code.to_s) end |
.parse(value) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/opencdd/irdi.rb', line 34 def self.parse(value) return nil if value.nil? s = value.to_s.strip return nil if s.empty? if (m = FULL_REGEX.match(s)) then from_match(m) elsif (m = TREE_REGEX.match(s)) then from_match(m) elsif SHORT_REGEX.match?(s) then from_short(s) elsif s.include?("#") && (m = FULL_REGEX.match(s.gsub(/\s+/, ""))) then from_match(m) else from_short(s) end end |
Instance Method Details
#==(other) ⇒ Object
115 116 117 |
# File 'lib/opencdd/irdi.rb', line 115 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
107 108 109 |
# File 'lib/opencdd/irdi.rb', line 107 def eql?(other) other.is_a?(Opencdd::IRDI) && to_s == other.to_s end |
#full? ⇒ Boolean
71 72 73 |
# File 'lib/opencdd/irdi.rb', line 71 def full? !@registrant.nil? end |
#hash ⇒ Object
111 112 113 |
# File 'lib/opencdd/irdi.rb', line 111 def hash to_s.hash end |
#inspect ⇒ Object
119 120 121 |
# File 'lib/opencdd/irdi.rb', line 119 def inspect "#<Opencdd::IRDI #{to_s.inspect}>" end |
#sheetmap_version ⇒ Object
81 82 83 |
# File 'lib/opencdd/irdi.rb', line 81 def sheetmap_version @version end |
#short? ⇒ Boolean
75 76 77 |
# File 'lib/opencdd/irdi.rb', line 75 def short? @registrant.nil? end |
#to_s ⇒ Object Also known as: to_str
85 86 87 88 |
# File 'lib/opencdd/irdi.rb', line 85 def to_s return @code if short? "#{@registrant}/#{@semantic}///#{@scheme}##{@code}" end |
#to_tree_path ⇒ Object
92 93 94 95 |
# File 'lib/opencdd/irdi.rb', line 92 def to_tree_path return @code if short? "#{@registrant}-#{@semantic}---#{@scheme}%23#{@code}" end |
#with_code(new_code) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/opencdd/irdi.rb', line 97 def with_code(new_code) self.class.new( registrant: @registrant, semantic: @semantic, scheme: @scheme, code: new_code.to_s, version: @version, ) end |