Class: URI::ACCT

Inherits:
Generic
  • Object
show all
Defined in:
lib/discodactyl/acct_uri.rb

Constant Summary collapse

COMPONENT =
[
  :scheme,
  :local_part, :host
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*arg) ⇒ ACCT

Returns a new instance of ACCT.


51
52
53
54
# File 'lib/discodactyl/acct_uri.rb', line 51

def initialize(*arg)
  super(*arg)
  parse_opaque
end

Instance Attribute Details

#local_partObject (readonly)

Returns the value of attribute local_part


63
64
65
# File 'lib/discodactyl/acct_uri.rb', line 63

def local_part
  @local_part
end

Class Method Details

.build(args) ⇒ Object

Description

Create a new URI::ACCT object from components, with syntax checking.

The components accepted are local-part and host.

The components should be provided either as an Array, or as a Hash with keys formed by preceding the component names with a colon.

If an Array is used, the components must be passed in the order [local-part, host].

Example:

newuri = URI::ACCT.build({:host => 'example.com',
  :local_part> => 'bob'})

newuri = URI::ACCT.build(['bob', "example.com"])

42
43
44
45
46
47
48
49
# File 'lib/discodactyl/acct_uri.rb', line 42

def self.build(args)
  tmp = Util::make_components_hash(self, args)
  if tmp[:local_part] && tmp[:host]
    tmp[:opaque] = tmp[:local_part]+'@'+tmp[:host]
    tmp[:host] = nil
  end
  return super(tmp)
end

.parse(str) ⇒ Object


12
13
14
15
16
17
18
19
# File 'lib/discodactyl/acct_uri.rb', line 12

def self.parse(str)
  /^(acct:)?(.*)$/ =~ str
  scheme = 'acct'
  opaque = $2
  acct = self.new(scheme, nil, nil, nil, nil, nil, opaque, nil, nil)
  Discodactyl.log.debug("Parsed #{str.inspect} into URI #{acct.inspect}") if Discodactyl.log
  acct
end

Instance Method Details

#heirarchical?Boolean

Returns:

  • (Boolean)

78
79
80
# File 'lib/discodactyl/acct_uri.rb', line 78

def heirarchical?
  false
end

#idObject


74
75
76
# File 'lib/discodactyl/acct_uri.rb', line 74

def id
  "#{@local_part}@#{@host}"
end

#parse_opaqueObject


56
57
58
59
60
61
# File 'lib/discodactyl/acct_uri.rb', line 56

def parse_opaque
  if /^([^@]*)@(.*)$/ =~ @opaque
    @local_part = $1
    @host = $2
  end
end

#to_sObject


70
71
72
# File 'lib/discodactyl/acct_uri.rb', line 70

def to_s
  "#{@scheme}:#{@local_part}@#{@host}"
end