Class: Ficsr::Session
- Inherits:
-
Object
- Object
- Ficsr::Session
- Defined in:
- lib/ficsr/session.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #games ⇒ Object
-
#initialize(username, password) ⇒ Session
constructor
A new instance of Session.
- #observe(game_number, &action) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Session
Returns a new instance of Session.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ficsr/session.rb', line 12 def initialize(username, password) @username = username @password = password send username, /password|is not a registered name/ if registered? send password, /fics|login/ else send "\n", /#{username}/ end raise "Unable to login with username #{username} " unless logged_in? end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/ficsr/session.rb', line 10 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/ficsr/session.rb', line 10 def username @username end |
Class Method Details
.login(username, password = "") ⇒ Object
5 6 7 |
# File 'lib/ficsr/session.rb', line 5 def login(username, password="") new(username, password) end |
Instance Method Details
#games ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ficsr/session.rb', line 26 def games send "games", /fics/ last_result.split("\n\r").select { |line| line =~ /^\d{3}\s\w{1,4}.*$/ }.collect do |game| Ficsr::Game.new game end end |
#observe(game_number, &action) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ficsr/session.rb', line 33 def observe(game_number, &action) t = Thread.new do send "observe #{game_number}", /fics/ last_result.each_line("\n\r") do |line| action.call(line) if line =~/^<12>/ end end t.join end |