Class: AP::Category

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Category

Creates a new AP::Category object given the following attributes

  • id: the category id as reported by the AP

  • title: the title/name of the category

  • content: the category content. most often is the same as the title

  • updated: Time object of when the article was last updated



11
12
13
14
15
16
# File 'lib/ap/category.rb', line 11

def initialize(opts = {})
  @id = opts[:id]
  @title = opts[:title]
  @content = opts[:content]
  @updated = opts[:updated]
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/ap/category.rb', line 3

def content
  @content
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/ap/category.rb', line 3

def id
  @id
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/ap/category.rb', line 3

def title
  @title
end

#updatedObject

Returns the value of attribute updated.



3
4
5
# File 'lib/ap/category.rb', line 3

def updated
  @updated
end

Class Method Details

.new_from_api_data(data) ⇒ Object

Creates a new object from data returned by the API



19
20
21
# File 'lib/ap/category.rb', line 19

def self.new_from_api_data(data)
  return new(:id => data["id"].split(":").last, :title => data["title"], :content => data["content"], :updated => Time.parse(data["updated"]))
end

Instance Method Details

#articlesObject

Returns an array of AP::Article objects that represent recent news in this category



24
25
26
# File 'lib/ap/category.rb', line 24

def articles
  return AP.category(@id)
end