Module: YahooSports

Defined in:
lib/yahoo_sports.rb,
lib/yahoo_sports/mlb.rb,
lib/yahoo_sports/nba.rb,
lib/yahoo_sports/nfl.rb,
lib/yahoo_sports/nhl.rb,
lib/yahoo_sports/base.rb

Defined Under Namespace

Classes: Base, MLB, NBA, NFL, NHL

Class Method Summary collapse

Class Method Details

.fetchurl(url) ⇒ String

Fetches the given URL and returns the body

Parameters:

  • URL (String)

Returns:

  • (String)

    contents of response body



16
17
18
19
# File 'lib/yahoo_sports/base.rb', line 16

def self.fetchurl(url)
    # puts "FETCHING: '#{url}'"
    return Net::HTTP.get_response(URI.parse(URI.escape(url))).body
end

.strip_tags(html) ⇒ String

Strip HTML tags from the given string. Also performs some common entity substitutions.

List of entity codes:

  •  

  • &

  • "

  • <

  • >

  • &ellip;

  • '

Parameters:

  • html (String)

    text to be filtered

Returns:

  • (String)

    original string with HTML tags filtered out and entities replaced



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/yahoo_sports/base.rb', line 35

def self.strip_tags(html)

    HTMLEntities.new.decode(
        html.gsub(/<.+?>/,'').
        gsub(/&nbsp;/,' ').
        gsub(/&amp;/,'&').
        gsub(/&quot;/,'"').
        gsub(/&lt;/,'<').
        gsub(/&gt;/,'>').
        gsub(/&ellip;/,'...').
        gsub(/&apos;/, "'").
        gsub(/<br *\/>/m, '')
    ).strip

end