Class: URI::URN::Generic

Inherits:
Generic
  • Object
show all
Defined in:
lib/uri/urn.rb

Direct Known Subclasses

UUID

Constant Summary collapse

COMPONENT =
URN::COMPONENT
NID_PATTERN =
'[\w\d][\w\d\-]{0,31}'.freeze
URN_CHARS_PATTERN =
"[\\w\\d()+,\\-.:=@;$_!*%/?#]|#{URI::PATTERN::ESCAPED}".freeze
NSS_PATTERN =
"(?:#{URN_CHARS_PATTERN})+".freeze
URN_REGEXP =
Regexp.new("\\A(?<nid>#{NID_PATTERN}):(?<nss>#{NSS_PATTERN})\\z").freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*arg) ⇒ Generic

Returns a new instance of Generic.



47
48
49
50
51
52
# File 'lib/uri/urn.rb', line 47

def initialize(*arg)
  super(*arg)
  if arg[-1]
    self.opaque = @opaque
  end
end

Instance Attribute Details

#nidObject

Returns the value of attribute nid.



29
30
31
# File 'lib/uri/urn.rb', line 29

def nid
  @nid
end

#nssObject

Returns the value of attribute nss.



29
30
31
# File 'lib/uri/urn.rb', line 29

def nss
  @nss
end

Class Method Details

.build(args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/uri/urn.rb', line 31

def self.build(args)
  nid = self.to_s.sub(/\A.*::/, '').downcase
  unless nid == 'generic'
    if args.kind_of?(Array)
      args = [nid] + args
    elsif args.kind_of?(Hash)
      args[:nid] = nid
    end
  end
  tmp = Util.make_components_hash(self, args)
  tmp[:scheme] = 'urn'
  tmp[:opaque] = "%{nid}:%{nss}" % tmp

  return super(tmp)
end

Instance Method Details

#normalize!Object



80
81
82
83
# File 'lib/uri/urn.rb', line 80

def normalize!
  super
  set_nid(self.nid.downcase)
end

#opaque=(value) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/uri/urn.rb', line 66

def opaque=(value)
  check_opaque(value)

  if URN_REGEXP =~ value
    self.nid = $~['nid']
    self.nss = $~['nss']
  else
    raise InvalidURIError, "bad URI(nid nor nss not set?): #{self}"
  end

  set_opaque(value)
  value
end