Skip to content

Commit

Permalink
Remove random <sp/> in player names that have clan tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbytables committed Apr 7, 2013
1 parent 2ea310f commit 7b71046
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
7 changes: 6 additions & 1 deletion lib/tassadar/sc2/player.rb
@@ -1,7 +1,8 @@
module Tassadar
module SC2
class Player
attr_accessor :name, :id, :won, :color, :chosen_race, :actual_race, :handicap, :team
attr_accessor :id, :won, :color, :chosen_race, :actual_race, :handicap, :team
attr_writer :name

def initialize(details_hash, attributes)
@name = details_hash[0]
Expand All @@ -18,6 +19,10 @@ def initialize(details_hash, attributes)
def winner?
@won
end

def name
@name.gsub("<sp/>","")
end
end
end
end
Binary file added spec/replays/game_with_clan_tag.SC2Replay
Binary file not shown.
39 changes: 23 additions & 16 deletions spec/tassadar/sc2/player_spec.rb
Expand Up @@ -2,52 +2,59 @@
require 'spec_helper'

describe Tassadar::SC2::Player do
subject(:player) { replay.players.last }

context 'NA SC2 Replay' do
before(:each) do
@replay = Tassadar::SC2::Replay.new(File.join(REPLAY_DIR, "OhanaLE.SC2Replay"))
@player = @replay.players.last
end
let(:replay) { Tassadar::SC2::Replay.new(File.join(REPLAY_DIR, "OhanaLE.SC2Replay")) }

it "should set the name" do
@player.name.should == "MLGLogan"
player.name.should == "MLGLogan"
end

it "should set the id" do
@player.id.should == 1485031
player.id.should == 1485031
end

it "should tell if the player won" do
@player.should_not be_winner
player.should_not be_winner
end

it "should have a color" do
@player.color.should == {:alpha => 255, :red => 0, :green => 66, :blue => 255}
player.color.should == {:alpha => 255, :red => 0, :green => 66, :blue => 255}
end

it "should have random as the chosen race if random" do
@player.chosen_race.should == "Random"
player.chosen_race.should == "Random"
end

it "should have an actual race" do
@player.actual_race.should == "Protoss"
player.actual_race.should == "Protoss"
end

it "should have a handicap" do
@player.handicap.should == 100
player.handicap.should == 100
end

it "should set the team" do
@player.team.should == 0
it "should set the team" do
player.team.should == 0
end
end

context 'EU SC2 Replay' do
let(:replay) { Tassadar::SC2::Replay.new(File.join(REPLAY_DIR, 'eu_replay.SC2Replay')) }
subject { replay.players.last }

it 'encodes the name in UTF-8' do
subject.name.encoding.to_s.should == 'UTF-8'
subject.name.should == 'MǂStephano'
player.name.encoding.to_s.should == 'UTF-8'
player.name.should == 'MǂStephano'
end
end

context "replay with a player who has a clan tag" do
let(:replay) { Tassadar::SC2::Replay.new(File.join(REPLAY_DIR, 'game_with_clan_tag.SC2Replay')) }
subject(:player) { replay.players.first }

it "returns the name without a <sp/>" do
expect(player.name).to eq("[JZTD]JZTD")
end
end
end

0 comments on commit 7b71046

Please sign in to comment.