Class: UniformResourceIdentifier::UserInfo
- Inherits:
-
Object
- Object
- UniformResourceIdentifier::UserInfo
- Extended by:
- Parsable
- Defined in:
- lib/uniform_resource_identifier/user_info.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
# = Attributes = # ======================================================================= #.
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(user_info = nil) ⇒ UserInfo
constructor
A new instance of UserInfo.
- #to_h ⇒ Object
- #to_s ⇒ Object
Methods included from Parsable
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(user_info=nil) if user_info.respond_to?(:to_str) @username, @password = user_info.to_str.split(":") elsif user_info.respond_to?(:to_hash) user_info.to_hash.symbolize_keys @username, @password = user_info.values_at(:username, :password) else raise(TypeError, "user_info must either be a String or a Hash") unless user_info.nil? end end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
38 39 40 |
# File 'lib/uniform_resource_identifier/user_info.rb', line 38 def password @password end |
#username ⇒ Object
#
Attributes = #
#
37 38 39 |
# File 'lib/uniform_resource_identifier/user_info.rb', line 37 def username @username end |
Instance Method Details
#blank? ⇒ Boolean
30 31 32 |
# File 'lib/uniform_resource_identifier/user_info.rb', line 30 def blank? @username.blank? && @password.blank? end |
#to_h ⇒ Object
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_s ⇒ Object
19 20 21 |
# File 'lib/uniform_resource_identifier/user_info.rb', line 19 def to_s "#{@username}:#{@password}" end |