Class: CeilingCat::User

Inherits:
Object
  • Object
show all
Defined in:
lib/ceiling_cat/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ User

Returns a new instance of User.



5
6
7
8
9
# File 'lib/ceiling_cat/user.rb', line 5

def initialize(name, opts={})
  @name = name
  @id = opts[:id] || rand(10000000)
  @role = opts[:role] || "guest"
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/ceiling_cat/user.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ceiling_cat/user.rb', line 3

def name
  @name
end

#roleObject

Returns the value of attribute role.



3
4
5
# File 'lib/ceiling_cat/user.rb', line 3

def role
  @role
end

Instance Method Details

#is_guest?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ceiling_cat/user.rb', line 23

def is_guest?
  @role.to_s.downcase == 'guest' || @type.to_s.nil?
end

#is_registered?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ceiling_cat/user.rb', line 19

def is_registered?
  @role.to_s.downcase == 'member'
end

#short_nameObject



15
16
17
# File 'lib/ceiling_cat/user.rb', line 15

def short_name
  @name.to_s.split.compact.first
end

#to_sObject



11
12
13
# File 'lib/ceiling_cat/user.rb', line 11

def to_s
  short_name
end