Class: HeadlineResponse::HeadlineItem

Inherits:
Object
  • Object
show all
Defined in:
lib/espn_rb/headline_item.rb,
lib/espn_rb/headline_image.rb

Defined Under Namespace

Classes: Image, Images

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ HeadlineItem

Returns a new instance of HeadlineItem.



5
6
7
# File 'lib/espn_rb/headline_item.rb', line 5

def initialize(opts)
  @headline = opts
end

Instance Attribute Details

#headlineObject (readonly)

Returns the value of attribute headline.



3
4
5
# File 'lib/espn_rb/headline_item.rb', line 3

def headline
  @headline
end

Instance Method Details

#api_urlString

Returns api_url for Item.

Examples:

espn = EspnRb.headlines
espn.nba.first.api_url => "http://some-valid-nba-article"

Returns:

  • (String)

    api_url for Item



69
70
71
# File 'lib/espn_rb/headline_item.rb', line 69

def api_url
  @headline["links"]["api"]["news"]["href"]
end

#athlete_idsObject

Provides access to categories sub-hash. If available

#=> [“123”, “132”, “123”]

Examples:

espn = EspnRb.headlines
espn.nba.first.athlete_ids


104
105
106
# File 'lib/espn_rb/headline_item.rb', line 104

def athlete_ids
  return collect_category(:athleteId)
end

#athletesObject

Provides access to categories sub-hash. If available

#=> [“Johnny B”, “Freddie Flintstone”, “Etc”]

Examples:

espn = EspnRb.headlines
espn.nba.first.athletes


84
85
86
# File 'lib/espn_rb/headline_item.rb', line 84

def athletes
  return collect_category(:description)
end

#categoriesObject



108
109
110
# File 'lib/espn_rb/headline_item.rb', line 108

def categories
  @headline["categories"]
end

#collect_category(sym) ⇒ Object



74
75
76
# File 'lib/espn_rb/headline_item.rb', line 74

def collect_category(sym)
  @headline["categories"].inject([]) {|m, i| m <<  i[sym.to_s] unless i[sym.to_s].nil?; m}
end

#descriptionString

Returns description for Item.

Examples:

espn = EspnRb.headlines
espn.ncaa_football.first.description => "Some string about what happened in the article."

Returns:

  • (String)

    description for Item



29
30
31
# File 'lib/espn_rb/headline_item.rb', line 29

def description
  @headline["description"]
end

#idInteger

Returns id for Item.

Examples:

espn = EspnRb.headlines
espn.ncaa_football.first.id => '1234'

Returns:

  • (Integer)

    id for Item



61
62
63
# File 'lib/espn_rb/headline_item.rb', line 61

def id
  @headline["id"]
end

#imagesImages

Returns Images class containing the collection of images associated with the item.

Examples:

espn = EspnRb.headlines
espn.ncaa_football.first.last_modified => "2012-03-16T04:07:56Z"

Returns:

  • (Images)

    Images class containing the collection of images associated with the item.



53
54
55
# File 'lib/espn_rb/headline_item.rb', line 53

def images
  Images.new @headline["images"]
end

#last_modifiedString

Returns title for Item.

Examples:

espn = EspnRb.headlines
espn.ncaa_football.first.last_modified => "2012-03-16T04:07:56Z"

Returns:

  • (String)

    title for Item



45
46
47
# File 'lib/espn_rb/headline_item.rb', line 45

def last_modified
  @headline["lastModified"]
end

#leaguesObject

Provides access to categories sub-hash. If available

#=> [“46”]

Examples:

espn = EspnRb.headlines
espn.nba.first.leagues


94
95
96
# File 'lib/espn_rb/headline_item.rb', line 94

def leagues
  return collect_category(:leagueId)
end

#sourceString

Returns source for Item.

Examples:

espn = EspnRb.headlines
espn.ncaa_football.first.source => "Page 2"

Returns:

  • (String)

    source for Item



37
38
39
# File 'lib/espn_rb/headline_item.rb', line 37

def source
  @headline["source"]
end

#titleString

Returns title for Item.

Examples:

espn = EspnRb.headlines
espn.ncaa_football.first.title => "Gators Win!!"

Returns:

  • (String)

    title for Item



21
22
23
# File 'lib/espn_rb/headline_item.rb', line 21

def title
  @headline["headline"]
end

#web_url(mobile = false) ⇒ String

Returns web_url for Item.

Examples:

espn = EspnRb.headlines
espn.nba.first.web_url => "http://some-valid-nba-article"

Returns:

  • (String)

    web_url for Item



13
14
15
# File 'lib/espn_rb/headline_item.rb', line 13

def web_url(mobile=false)
  (mobile == true) ? @headline["links"]["mobile"]["href"] : @headline["links"]["web"]["href"]
end