diff --git a/lib/tassadar/sc2/player.rb b/lib/tassadar/sc2/player.rb index dc89491..db9a4d8 100644 --- a/lib/tassadar/sc2/player.rb +++ b/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] @@ -18,6 +19,10 @@ def initialize(details_hash, attributes) def winner? @won end + + def name + @name.gsub("","") + end end end end diff --git a/spec/replays/game_with_clan_tag.SC2Replay b/spec/replays/game_with_clan_tag.SC2Replay new file mode 100644 index 0000000..8d1256a Binary files /dev/null and b/spec/replays/game_with_clan_tag.SC2Replay differ diff --git a/spec/tassadar/sc2/player_spec.rb b/spec/tassadar/sc2/player_spec.rb index 5513848..d4c90a0 100644 --- a/spec/tassadar/sc2/player_spec.rb +++ b/spec/tassadar/sc2/player_spec.rb @@ -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 " do + expect(player.name).to eq("[JZTD]JZTD") end end end