Class: Twterm::User

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

Constant Summary collapse

COLORS =
[:red, :blue, :green, :cyan, :yellow, :magenta]
@@instances =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ User

Returns a new instance of User.



18
19
20
21
22
23
24
# File 'lib/twterm/user.rb', line 18

def initialize(user)
  @id = user.id
  update!(user)
  @color = COLORS[@id % 6]

  @@instances << self
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



4
5
6
# File 'lib/twterm/user.rb', line 4

def color
  @color
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#followers_countObject (readonly)

Returns the value of attribute followers_count.



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

def followers_count
  @followers_count
end

#followingObject (readonly) Also known as: following?

Returns the value of attribute following.



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

def following
  @following
end

#friends_countObject (readonly)

Returns the value of attribute friends_count.



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

def friends_count
  @friends_count
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#locationObject (readonly)

Returns the value of attribute location.



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

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#protectedObject (readonly) Also known as: protected?

Returns the value of attribute protected.



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

def protected
  @protected
end

#screen_nameObject (readonly)

Returns the value of attribute screen_name.



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

def screen_name
  @screen_name
end

#statuses_countObject (readonly)

Returns the value of attribute statuses_count.



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

def statuses_count
  @statuses_count
end

#websiteObject (readonly)

Returns the value of attribute website.



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

def website
  @website
end

Class Method Details

.new(user) ⇒ Object



12
13
14
15
16
# File 'lib/twterm/user.rb', line 12

def self.new(user)
  detector = -> (instance) { instance.id == user.id }
  instance = @@instances.find(&detector)
  instance.nil? ? super : instance.update!(user)
end

Instance Method Details

#update!(user) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/twterm/user.rb', line 26

def update!(user)
  @name = user.name
  @screen_name = user.screen_name
  @description = user.description || ''
  @location = user.location.is_a?(Twitter::NullObject) ? '' : user.location
  @website = user.website
  @following = user.following?
  @protected = user.protected?
  @statuses_count = user.statuses_count
  @friends_count = user.friends_count
  @followers_count = user.followers_count
  self
end