Class: XblGamercard::Gamercard
- Inherits:
-
Object
- Object
- XblGamercard::Gamercard
- Includes:
- MicroScraper
- Defined in:
- lib/xbl_gamercard/gamercard.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
Returns the value of attribute element.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(html) ⇒ Gamercard
constructor
A new instance of Gamercard.
- #played_games ⇒ Object
Methods included from MicroScraper
Constructor Details
#initialize(html) ⇒ Gamercard
Returns a new instance of Gamercard.
11 12 13 |
# File 'lib/xbl_gamercard/gamercard.rb', line 11 def initialize(html) @element = Nokogiri::HTML(html) end |
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
9 10 11 |
# File 'lib/xbl_gamercard/gamercard.rb', line 9 def element @element end |
Class Method Details
.fetch(gamertag) ⇒ Object
33 34 35 36 37 |
# File 'lib/xbl_gamercard/gamercard.rb', line 33 def self.fetch(gamertag) uri = URI(self.url_for(gamertag)) contents = Net::HTTP.get_response(uri) return self.new(contents.body) end |
.url_for(gamertag) ⇒ Object
39 40 41 42 |
# File 'lib/xbl_gamercard/gamercard.rb', line 39 def self.url_for(gamertag) # Use URI.escape because we actually want percent encoding (%20 for space instead of +) return "http://gamercard.xbox.com/en-US/#{URI.escape(gamertag)}.card" end |
Instance Method Details
#played_games ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/xbl_gamercard/gamercard.rb', line 23 def played_games return element.css("ol#PlayedGames>li").select { |e| # This is annoyingly hard to express using MicroScraper on older # versions of Nokogiri... e["class"] != "Unplayed" }.map { |e| XblGamercard::GamercardGame.new(e) } end |