Class: Upcoming::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/upcoming/category.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, description) ⇒ Category

Returns a new instance of Category.



9
10
11
12
13
# File 'lib/upcoming/category.rb', line 9

def initialize(id, name, description)
  @id = id.to_i
  @name = name
  @description = description
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/upcoming/category.rb', line 7

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/upcoming/category.rb', line 7

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/upcoming/category.rb', line 7

def name
  @name
end

Class Method Details

.info(category_id) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/upcoming/category.rb', line 15

def self.info(category_id)
  Category.list.each do |cat|
    return cat if cat.id == category_id.to_i
  end
  
  nil
end

.listObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/upcoming/category.rb', line 23

def self.list
  categories = []
  
  req = Upcoming::Request.new
  resp = req.send({:method => 'category.getList'})
  
  doc = Document.new(resp.body)
  XPath.each(doc, '//category') do |el|
    categories << Category.new(el.attribute('id').value,
        el.attribute('name').value, el.attribute('description').value)
  end
  
  categories
end