Class: Fetion::BuddyList

Inherits:
Object
  • Object
show all
Defined in:
lib/rfetion/buddy_list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bid, name) ⇒ BuddyList

Returns a new instance of BuddyList.



5
6
7
8
9
# File 'lib/rfetion/buddy_list.rb', line 5

def initialize(bid, name)
  @bid = bid
  @name = name
  @contacts = []
end

Instance Attribute Details

#bidObject (readonly)

Returns the value of attribute bid.



3
4
5
# File 'lib/rfetion/buddy_list.rb', line 3

def bid
  @bid
end

#contactsObject (readonly)

Returns the value of attribute contacts.



3
4
5
# File 'lib/rfetion/buddy_list.rb', line 3

def contacts
  @contacts
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rfetion/buddy_list.rb', line 3

def name
  @name
end

Class Method Details

.parse(buddy_list) ⇒ Object



15
16
17
# File 'lib/rfetion/buddy_list.rb', line 15

def self.parse(buddy_list)
  self.new(buddy_list['id'], buddy_list['name'])
end

Instance Method Details

#add_contact(contact) ⇒ Object



19
20
21
# File 'lib/rfetion/buddy_list.rb', line 19

def add_contact(contact)
  @contacts << contact
end

#online_contacts_countObject



23
24
25
# File 'lib/rfetion/buddy_list.rb', line 23

def online_contacts_count
  @contacts.select {|contact| contact.status == "400"}.size
end

#to_json(*args) ⇒ Object



11
12
13
# File 'lib/rfetion/buddy_list.rb', line 11

def to_json(*args)
  {:bid => @bid, :name => @name, :contacts => @contacts, :total_contacts => total_contacts_count, :online_contacts => online_contacts_count}.to_json(*args)
end

#total_contacts_countObject



27
28
29
# File 'lib/rfetion/buddy_list.rb', line 27

def total_contacts_count
  @contacts.size
end