class AP::Category

Attributes

content[RW]
id[RW]
title[RW]
updated[RW]

Public Class Methods

new(opts = {}) click to toggle source

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

# File lib/ap/category.rb, line 11
def initialize(opts = {})
  @id = opts[:id]
  @title = opts[:title]
  @content = opts[:content]
  @updated = opts[:updated]
end
new_from_api_data(data) click to toggle source

Creates a new object from data returned by the API

# 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

Public Instance Methods

articles() click to toggle source

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

# File lib/ap/category.rb, line 24
def articles
  return AP.category(@id)
end