Class: Alt::URI::Gen::UserInfoParts

Inherits:
Base show all
Defined in:
lib/rio/alturi/uri_parts.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#_do_esc, #_do_unesc, #nil_or

Constructor Details

#initializeUserInfoParts

Returns a new instance of UserInfoParts.



115
116
117
# File 'lib/rio/alturi/uri_parts.rb', line 115

def initialize
  @store = {}
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



114
115
116
# File 'lib/rio/alturi/uri_parts.rb', line 114

def store
  @store
end

Class Method Details

.parse(val) ⇒ Object



122
123
124
125
126
127
128
129
130
# File 'lib/rio/alturi/uri_parts.rb', line 122

def self.parse(val)
  ui = new
  if val
    us,pw = val.split(':',2)
    ui.store[:user] = us
    ui.store[:password] = pw
  end
  ui
end

Instance Method Details

#==(other) ⇒ Object



131
132
133
# File 'lib/rio/alturi/uri_parts.rb', line 131

def ==(other)
  @store == other.store
end

#[](sym) ⇒ Object



134
135
136
# File 'lib/rio/alturi/uri_parts.rb', line 134

def [](sym)
  @store[sym]
end

#[]=(sym, val) ⇒ Object



138
139
140
# File 'lib/rio/alturi/uri_parts.rb', line 138

def []=(sym,val)
  @store[sym] = val
end

#initialize_copy(other) ⇒ Object



118
119
120
121
# File 'lib/rio/alturi/uri_parts.rb', line 118

def initialize_copy(other)
  super
  @store = other.store.dup
end

#passwordObject



156
157
158
# File 'lib/rio/alturi/uri_parts.rb', line 156

def password
   @store[:password]
end

#password=(val) ⇒ Object



152
153
154
# File 'lib/rio/alturi/uri_parts.rb', line 152

def password=(val)
  @store[:password] = val
end

#to_sObject



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/rio/alturi/uri_parts.rb', line 162

def to_s
  # RFC 3986 3.2.1
  # Use of the format "user:password" in the userinfo field is
  # deprecated.  Applications should not render as clear text any data
  # after the first colon (":") character found within a userinfo
  # subcomponent unless the data after the colon is the empty string
  # (indicating no password).
  u = @store[:user]
  passwd = ':' if @store[:password] and @store[:password].empty?
  "#{u}#{passwd}"
end

#userObject



144
145
146
# File 'lib/rio/alturi/uri_parts.rb', line 144

def user
  _do_unesc(@store[:user])
end

#user=(val) ⇒ Object



147
148
149
150
151
# File 'lib/rio/alturi/uri_parts.rb', line 147

def user=(val)
  @store[:user] = nil_or(val) { |v| 
    _do_esc(v,:user) 
  }
end

#valueObject



159
160
161
# File 'lib/rio/alturi/uri_parts.rb', line 159

def value
  self.to_s if @store[:user]
end