4f5d54213efb6502baab202f3fb2f09e

Can't help but feel I might be doing this wrong?
Anyone care to shed some light.

class SteamController < ApplicationController
require 'rubygems'
require 'scrubyt'

	def index
		@steam_data = get_steam_data(params[:steam_id])
	end

private

	def get_steam_data(steam_id)
		steam_data = Scrubyt::Extractor.define do
			fetch 'http://steamcommunity.com/id/' << steam_id
			friendly_name "//div[@id='mainContents']/h1[1]"
			last_online "//p[@id='statusOfflineText'][1]"
			member_since "//div[@class='statsItem'][1]"
			steam_rating "//div[@class='statsItem'][3]"
			playing_time "//div[@class='statsItem'][5]"
			image "//div[@id='profileAvatar']/div/div/img[1]" do
				image_src "src", :type => :attribute
			end
			link "//div[@id='rightActionBlock']/div/a[1]" do
				add_link "href", :type => :attribute
			end
		end
		steam_data = steam_data.to_hash
	end

end
<h1><%= @steam_data[0][:friendly_name] %></h1>
<p><%= link_to 'Goto ' << @steam_data[0][:friendly_name].pluralize << ' Steam profile', 'http://steamcommunity.com/id/' << params[:steam_id] %></p>
<p><%= link_to 'Add ' << @steam_data[0][:friendly_name] << ' as a Steam friend', @steam_data[5][:add_link] %></p>
<p><%= image_tag @steam_data[4][:image_src] %></p>
<p><%= debug @steam_data %></p>

Refactorings

No refactoring yet !

A8d3f35baafdaea851914b17dae9e1fc

Adam

December 19, 2008, December 19, 2008 04:29, permalink

No rating. Login to rate!

You need a model.

class SteamData < OpenStruct
  class << self
    def find(id)
      # You may have to massage the results from to_hash
      new extract_steam_data(id).to_hash
    end

    def extract_steam_data(id)
      Scrubyt::Extractor.define do
        fetch profile_url(id)
  
        # Clipped for brevity ...
      end
    end

    def profile_url(id)
      "http://steamcommunity.com/id/#{id}"
    end
  end
  
  def profile_url
    self.class.profile_url(id)
  end
end
class SteamDataController < ApplicationController
  def show
    @steam_data = SteamData.find(params[:id])
  end
end
<h1><%=h @steam_data.friendly_name %></h1>

<p>
  <% link_to @steam_data.profile_url do %>
    Goto <%=h @steam_data.friendly_name.pluralize %> Steam profile
  <% end %>
</p>

<p>
  <% link_to @steam_data.add_link do %>
    Add <%=h @steam_data.friendly_name %> as a Steam friend
  <% end %>
</p>

<p>
  <%= image_tag @steam_data.image_src %>
</p>
4f5d54213efb6502baab202f3fb2f09e

sfusion.myopenid.com

December 19, 2008, December 19, 2008 17:38, permalink

No rating. Login to rate!

still getting hassle with array indexes in the view. any ideas?

<%= image_tag @steam_data[4][:image_src] %> # works

<%= image_tag @steam_data.image_src %> # doesn't work
A8d3f35baafdaea851914b17dae9e1fc

Adam

December 21, 2008, December 21, 2008 20:19, permalink

No rating. Login to rate!

Like I noted in the comments, you will probably need to "massage" the results from Scrubt::Extractor. I have no idea what the results look like, but if it's just an array of hashes that needs to be merged, try this:

class SteamData < OpenStruct
  class << self
    def find(id)
      # You may have to massage the results from to_hash
      new extract_steam_data(id).to_hash.inject({}) { |hash,element| hash.merge!(element) }
    end

    # ...
462df588645aba119c15451c720b5b3e

Paul

April 2, 2010, April 02, 2010 01:44, permalink

No rating. Login to rate!

Agence de Location de voitures au Maroc
Site Web a vendre concu pour les agences de location

9fa8d709b150fc2916937ba921a9ab1e

Jesica

April 13, 2010, April 13, 2010 20:17, permalink

No rating. Login to rate!

Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
http://www.vitalti.com

Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
Terapia psicologica en monterrey, psicologos en monterrey, zona centro, informes y citas tel. 1777-0678
C642cff5ca1baf134eba33c580d5410c

lorenzo

May 8, 2010, May 08, 2010 18:40, permalink

No rating. Login to rate!

case vacanze affitto appartamenti annunci da Privati Toscana offerte vacanze
case vacanze affitto appartamenti annunci da Privati Toscana offerte vacanze
http://www.affittocasevacanze.net

Your refactoring





Format Copy from initial code

or Cancel