Class: AP::Article
- Inherits:
-
Object
- Object
- AP::Article
- Defined in:
- lib/ap/article.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#content ⇒ Object
Returns the value of attribute content.
-
#id ⇒ Object
Returns the value of attribute id.
-
#link ⇒ Object
Returns the value of attribute link.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#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
-
#initialize(opts = {}) ⇒ Article
constructor
Creates a new AP::Article object given the following attributes - id: the article id as reported by the AP - title: the title of the article - authors: an Array of the name(s) of the author(s) of this article - tags: and array of tags or categories that have been attached to this article - link: string with the hosted version on the AP site - content: the article content - updated: Time object of when the article was last updated.
-
#similar ⇒ Object
Returns a search object that when fetched, will find articles similar to this one.
Constructor Details
#initialize(opts = {}) ⇒ Article
Creates a new AP::Article object given the following attributes
-
id: the article id as reported by the AP
-
title: the title of the article
-
authors: an Array of the name(s) of the author(s) of this article
-
tags: and array of tags or categories that have been attached to this article
-
link: string with the hosted version on the AP site
-
content: the article content
-
updated: Time object of when the article was last updated
13 14 15 16 17 18 19 20 21 |
# File 'lib/ap/article.rb', line 13 def initialize(opts = {}) @id = opts[:id] @title = opts[:title] @tags = opts[:tags] || [] @authors = opts[:authors] || [] @link = opts[:link] @content = opts[:content] @updated = opts[:updated] end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
3 4 5 |
# File 'lib/ap/article.rb', line 3 def @authors end |
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/ap/article.rb', line 3 def content @content end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/ap/article.rb', line 3 def id @id end |
#link ⇒ Object
Returns the value of attribute link.
3 4 5 |
# File 'lib/ap/article.rb', line 3 def link @link end |
#tags ⇒ Object
Returns the value of attribute tags.
3 4 5 |
# File 'lib/ap/article.rb', line 3 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/ap/article.rb', line 3 def title @title end |
#updated ⇒ Object
Returns the value of attribute updated.
3 4 5 |
# File 'lib/ap/article.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
24 25 26 27 28 29 30 31 32 |
# File 'lib/ap/article.rb', line 24 def self.new_from_api_data(data) if data["author"].is_a?(Hash) = [ data["author"]["name"] ] elsif data["author"].is_a?(Array) = data["author"].collect{ |x| x["name"] } end categories = data["category"] ? data["category"].collect { |x| x["label"] } : [] return new(:id => data["id"].split(":").last, :title => data["title"], :authors => , :tags => categories, :link => data["link"]["href"], :content => data["content"], :updated => Time.parse(data["updated"])) end |