Class: Daneel::User
- Inherits:
-
Object
- Object
- Daneel::User
- Defined in:
- lib/daneel/user.rb
Overview
Represents a generic user. Doesn’t have a room, because multiple rooms can contain the same user. The user’s unique identifier is supplied by the adapter, and only needs to be unique within the context of that adapter.
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#initials ⇒ Object
Returns the value of attribute initials.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#short_name ⇒ Object
Returns the value of attribute short_name.
Instance Method Summary collapse
-
#initialize(id, name, data = nil) ⇒ User
constructor
A new instance of User.
- #to_s ⇒ Object
Constructor Details
#initialize(id, name, data = nil) ⇒ User
Returns a new instance of User.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/daneel/user.rb', line 10 def initialize(id, name, data = nil) @id, @name, @data = id, name, data # First, try to get initials from the upper-case letters @initials = name.gsub(/\P{Upper}/,'') # If that fails, just go with the first letter of each word @initials = name.gsub(/(?<!^|\s)./,'') if @initials.empty? # Short name is just the bit up to the first space @short_name = name.match(/^(\S+)/)[0] end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/daneel/user.rb', line 8 def data @data end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/daneel/user.rb', line 7 def id @id end |
#initials ⇒ Object
Returns the value of attribute initials.
8 9 10 |
# File 'lib/daneel/user.rb', line 8 def initials @initials end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/daneel/user.rb', line 7 def name @name end |
#short_name ⇒ Object
Returns the value of attribute short_name.
8 9 10 |
# File 'lib/daneel/user.rb', line 8 def short_name @short_name end |
Instance Method Details
#to_s ⇒ Object
21 22 23 |
# File 'lib/daneel/user.rb', line 21 def to_s [short_name, short_name.downcase, initials].sample end |