Class: HeadlineResponse::HeadlineItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ 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::Headline
espn.nba.first.api_url => "http://some-valid-nba-article"


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

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::Headline
espn.nba.first.athlete_ids


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

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::Headline
espn.nba.first.athletes


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

def athletes
  return collect_category(:description)
end

#categoriesObject



77
78
79
# File 'lib/espn_rb/headline_item.rb', line 77

def categories
  @headline["categories"]
end

#collect_category(sym) ⇒ Object



43
44
45
# File 'lib/espn_rb/headline_item.rb', line 43

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

#idInteger

Returns id for Item.

Examples:

espn = EspnRb::Headline
espn.ncaa_football.first.id => 1234


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

def id
  @headline["id"]
end

#leaguesObject

Provides access to categories sub-hash. If available

#=> [“46”]

Examples:

espn = EspnRb::Headline
espn.nba.first.leagues


63
64
65
# File 'lib/espn_rb/headline_item.rb', line 63

def leagues
  return collect_category(:leagueId)
end

#titleString

Returns title for Item.

Examples:

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


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::Headline
espn.nba.first.web_url => "http://some-valid-nba-article"


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