Class: Twterm::List

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

Constant Summary collapse

@@instances =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list) ⇒ List

Returns a new instance of List.



7
8
9
10
11
12
13
# File 'lib/twterm/list.rb', line 7

def initialize(list)
  @id = list.id
  update!(list)

  @@instances[@id] = self
  self
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



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

def full_name
  @full_name
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#member_countObject (readonly)

Returns the value of attribute member_count.



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

def member_count
  @member_count
end

#modeObject (readonly)

Returns the value of attribute mode.



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

def mode
  @mode
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#slugObject (readonly)

Returns the value of attribute slug.



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

def slug
  @slug
end

#subscriber_countObject (readonly)

Returns the value of attribute subscriber_count.



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

def subscriber_count
  @subscriber_count
end

Class Method Details

.allObject



47
48
49
# File 'lib/twterm/list.rb', line 47

def self.all
  @@instances.values
end

.find(id) ⇒ Object



36
37
38
# File 'lib/twterm/list.rb', line 36

def self.find(id)
  @@instances[id]
end

.find_or_fetch(id) ⇒ Object



40
41
42
43
44
45
# File 'lib/twterm/list.rb', line 40

def self.find_or_fetch(id)
  instance = find(id)
  (yield(instance) && return) if instance

  Client.current.list(id) { |list| yield list }
end

.new(list) ⇒ Object



31
32
33
34
# File 'lib/twterm/list.rb', line 31

def self.new(list)
  instance = find(list.id)
  instance.nil? ? super : instance.update!(list)
end

Instance Method Details

#==(other) ⇒ Object



27
28
29
# File 'lib/twterm/list.rb', line 27

def ==(other)
  other.is_a?(self.class) && id == other.id
end

#update!(list) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/twterm/list.rb', line 15

def update!(list)
  @name = list.name
  @slug = list.slug
  @full_name = list.full_name
  @mode = list.mode
  @description = list.description.is_a?(Twitter::NullObject) ? '' : list.description
  @member_count = list.member_count
  @subscriber_count = list.subscriber_count

  self
end