Class: Twterm::List
- Inherits:
-
Object
- Object
- Twterm::List
- Defined in:
- lib/twterm/list.rb
Constant Summary collapse
- @@instances =
{}
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#member_count ⇒ Object
readonly
Returns the value of attribute member_count.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#subscriber_count ⇒ Object
readonly
Returns the value of attribute subscriber_count.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(list) ⇒ List
constructor
A new instance of List.
- #matches?(query) ⇒ Boolean
- #update!(list) ⇒ Object
Constructor Details
#initialize(list) ⇒ List
Returns a new instance of List.
11 12 13 14 15 16 17 |
# File 'lib/twterm/list.rb', line 11 def initialize(list) @id = list.id update!(list) @@instances[@id] = self self end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/twterm/list.rb', line 3 def description @description end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
3 4 5 |
# File 'lib/twterm/list.rb', line 3 def full_name @full_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/twterm/list.rb', line 3 def id @id end |
#member_count ⇒ Object (readonly)
Returns the value of attribute member_count.
3 4 5 |
# File 'lib/twterm/list.rb', line 3 def member_count @member_count end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
3 4 5 |
# File 'lib/twterm/list.rb', line 3 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/twterm/list.rb', line 3 def name @name end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
3 4 5 |
# File 'lib/twterm/list.rb', line 3 def slug @slug end |
#subscriber_count ⇒ Object (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
.all ⇒ Object
35 36 37 |
# File 'lib/twterm/list.rb', line 35 def self.all @@instances.values end |
.find(id) ⇒ Object
39 40 41 |
# File 'lib/twterm/list.rb', line 39 def self.find(id) @@instances[id] end |
.find_or_fetch(id) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/twterm/list.rb', line 43 def self.find_or_fetch(id) Promise.new do |resolve, reject| instance = find(id) (resolve.(instance) && next) if instance Client.current.list(id).then { |list| resolve.(list) } end end |
.new(list) ⇒ Object
52 53 54 55 |
# File 'lib/twterm/list.rb', line 52 def self.new(list) instance = find(list.id) instance.nil? ? super : instance.update!(list) end |
Instance Method Details
#==(other) ⇒ Object
7 8 9 |
# File 'lib/twterm/list.rb', line 7 def ==(other) other.is_a?(self.class) && id == other.id end |
#matches?(query) ⇒ Boolean
19 20 21 |
# File 'lib/twterm/list.rb', line 19 def matches?(query) [full_name, description].any? { |x| x.downcase.include?(query.downcase) } end |
#update!(list) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/twterm/list.rb', line 23 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 |