Class: SteamProfile
- Inherits:
-
Object
- Object
- SteamProfile
- Defined in:
- lib/steamprofile.rb
Instance Method Summary collapse
- #field ⇒ Object
-
#initialize(config) ⇒ SteamProfile
constructor
A new instance of SteamProfile.
- #nokogiri ⇒ Object
- #stripcdata(s) ⇒ Object
Constructor Details
#initialize(config) ⇒ SteamProfile
Returns a new instance of SteamProfile.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/steamprofile.rb', line 6 def initialize(config) #Set caching to false unless specified config[:cache] ||= false #Make sure the profile url has been supplied and is valid unless config[:profile_url] config[:error] = "No Profile URL Specified" else unless config[:profile_url] =~ /^http:\/\/steamcommunity\.com\/[id|profiles]/ then config[:error] = "Mal-Formed Profile URL" else config[:xml_url] = config[:profile_url] + "?xml=1" end end #Instanize the config array @config=config #Load Up Nokogiri unless config[:error] @nokogiri=Nokogiri::XML::Reader(open(config[:xml_url])) end self.nokogiri end |
Instance Method Details
#field ⇒ Object
28 29 30 |
# File 'lib/steamprofile.rb', line 28 def field return @fields end |
#nokogiri ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/steamprofile.rb', line 32 def nokogiri @fields={} @fields[:game]=[] @fields[:game_hours_played]=[] gi=0 ghpi=0 @nokogiri.each do |node| if node.name == "steamID" then @fields[:name] ||= self.stripcdata(node.inner_xml) elsif node.name == "gameName" then if gi != 3 && node.inner_xml != "" then @fields[:game][gi] ||= self.stripcdata(node.inner_xml) gi+=1 end elsif node.name == "hoursPlayed" then if ghpi != 3 && node.inner_xml != "" then @fields[:game_hours_played][ghpi] ||= node.inner_xml ghpi+=1 end elsif node.name == "onlineState" then @fields[:online_state] ||= node.inner_xml elsif node.name == "stateMessage" then @fields[:state_message] ||= self.stripcdata(node.inner_xml) elsif node.name == "avatarIcon" then @fields[:avatar] ||= self.stripcdata(node.inner_xml) @fields[:avatar_med] ||= @fields[:avatar].gsub(/\.jpg/,"_medium.jpg") @fields[:avatar_full] ||= @fields[:avatar].gsub(/\.jpg/,"_full.jpg") end end end |
#stripcdata(s) ⇒ Object
62 63 64 |
# File 'lib/steamprofile.rb', line 62 def stripcdata(s) s.scan(/<!\[CDATA\[(.*?)\]\]>/).join end |