Class: Osrs::Player
- Inherits:
-
Object
- Object
- Osrs::Player
- Defined in:
- lib/osrshighscores/player.rb
Constant Summary collapse
- @@lookup_url =
"http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player="
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#raw_stats ⇒ Object
readonly
Returns the value of attribute raw_stats.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #fetch_highscores ⇒ Object
-
#initialize(name) ⇒ Player
constructor
A new instance of Player.
- #validate_name ⇒ Object
Constructor Details
#initialize(name) ⇒ Player
Returns a new instance of Player.
9 10 11 12 |
# File 'lib/osrshighscores/player.rb', line 9 def initialize name @name = name validate_name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/osrshighscores/player.rb', line 7 def name @name end |
#raw_stats ⇒ Object (readonly)
Returns the value of attribute raw_stats.
7 8 9 |
# File 'lib/osrshighscores/player.rb', line 7 def raw_stats @raw_stats end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
7 8 9 |
# File 'lib/osrshighscores/player.rb', line 7 def stats @stats end |
Instance Method Details
#fetch_highscores ⇒ Object
23 24 25 26 27 28 |
# File 'lib/osrshighscores/player.rb', line 23 def fetch_highscores f = open(@@lookup_url + @name, "User-Agent" => "Ruby/OSRSGrabber") @raw_stats = f.readlines.map &:chomp # Readlines preserves newlines?? @stats = Osrs::Stats.new @raw_stats end |
#validate_name ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/osrshighscores/player.rb', line 14 def validate_name raise "invalid characters in name" if @name =~ /[^A-Za-z0-9_\- ]/ raise "name too long" if @name.length > 12 raise "name too short" if @name.length < 1 raise "name starts/ends with a space character" if (name[0] + name[-1]) =~ /[_\- ]/ end |