Class: UniformResourceIdentifier::UserInfo

Inherits:
Object
  • Object
show all
Extended by:
Parsable
Defined in:
lib/uniform_resource_identifier/user_info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parsable

parse

Constructor Details

#initialize(user_info = nil) ⇒ UserInfo

Returns a new instance of UserInfo.



8
9
10
11
12
13
14
15
16
17
# File 'lib/uniform_resource_identifier/user_info.rb', line 8

def initialize(=nil)
  if .respond_to?(:to_str) 
    @username, @password = .to_str.split(":")
  elsif .respond_to?(:to_hash)
    .to_hash.symbolize_keys
    @username, @password = .values_at(:username, :password)
  else
    raise(TypeError, "user_info must either be a String or a Hash") unless .nil?
  end
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



38
39
40
# File 'lib/uniform_resource_identifier/user_info.rb', line 38

def password
  @password
end

#usernameObject

#

Attributes = #

#


37
38
39
# File 'lib/uniform_resource_identifier/user_info.rb', line 37

def username
  @username
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/uniform_resource_identifier/user_info.rb', line 30

def blank?
  @username.blank? && @password.blank?
end

#to_hObject



23
24
25
26
27
28
# File 'lib/uniform_resource_identifier/user_info.rb', line 23

def to_h
  {
    :username => @username,
    :password => @password
  }
end

#to_sObject



19
20
21
# File 'lib/uniform_resource_identifier/user_info.rb', line 19

def to_s
  "#{@username}:#{@password}"
end