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



22
23
24
25
# File 'lib/yahoo_sports/base.rb', line 22

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/yahoo_sports/base.rb', line 41

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