Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Spun off get_steam_id to SteamUtil module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jschuur committed Sep 21, 2011
1 parent 408c8d0 commit c01c05d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -8,7 +8,7 @@ gem 'rails', '3.1.0'
gem 'mysql2'
gem 'steam-condenser'
gem 'sparklines'
gem 'rmagick'
gem 'rmagick', :require => false
gem 'omniauth'
gem 'redis'
gem 'coffeebeans'
Expand Down
13 changes: 3 additions & 10 deletions app/models/achievements.rb
@@ -1,5 +1,6 @@
class Achievements
attr_reader :error, :id
include SteamUtil

def initialize(user, game)
if @achievements = load_game_achievements(user, game)
Expand All @@ -9,11 +10,7 @@ def initialize(user, game)
achievements_per_day = @unlocked.map(&:timestamp).compact.reduce(Hash.new(0)) { |hash, timestamp| hash[timestamp.strftime("%D")] += 1; hash }
@sparkline_history = (Date.today-28 .. Date.today).map { |d| achievements_per_day[d.strftime("%D")] }

if user.to_i.to_s == user
@id = SteamId.new(user.to_i)
else
@id = SteamId.new(user)
end
@id = get_steam_id(user)
end
end

Expand All @@ -36,11 +33,7 @@ def load_game_achievements(user, game)
Marshal.load(cached_achievements)
else
begin
if user.to_i.to_s == user
id = SteamId.new(user.to_i)
else
id = SteamId.new(user)
end
id = get_steam_id(user)

# Save any profile we did a lookup on for later
User.create_with_id(id)
Expand Down
9 changes: 3 additions & 6 deletions app/models/friends.rb
@@ -1,11 +1,8 @@
class Friends
include SteamUtil

def initialize(user)
if user.to_i.to_s == user
id = SteamId.new(user.to_i)
else
id = SteamId.new(user)
end

id = get_steam_id(user)
load_friends(id)
end

Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Expand Up @@ -16,7 +16,7 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded.

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib)

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
Expand Down
9 changes: 9 additions & 0 deletions lib/steam_util.rb
@@ -0,0 +1,9 @@
module SteamUtil
def get_steam_id(user)
if user.to_i.to_s == user
SteamId.new(user.to_i)
else
SteamId.new(user)
end
end
end

0 comments on commit c01c05d

Please sign in to comment.