Class: AP::Category
- Inherits:
-
Object
- Object
- AP::Category
- Defined in:
- lib/ap/category.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated ⇒ Object
Returns the value of attribute updated.
Class Method Summary collapse
-
.new_from_api_data(data) ⇒ Object
Creates a new object from data returned by the API.
Instance Method Summary collapse
-
#articles ⇒ Object
Returns an array of AP::Article objects that represent recent news in this category.
-
#initialize(opts = {}) ⇒ Category
constructor
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.
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
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/ap/category.rb', line 3 def content @content end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/ap/category.rb', line 3 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/ap/category.rb', line 3 def title @title end |
#updated ⇒ Object
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
#articles ⇒ Object
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 |