Class: Ankit::Challenge::State

Inherits:
Object
  • Object
show all
Defined in:
lib/ankit/challenge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(progress, last_answer = nil) ⇒ State

Returns a new instance of State.



226
227
228
# File 'lib/ankit/challenge.rb', line 226

def initialize(progress, last_answer=nil)
  @progress, @last_answer = progress, last_answer
end

Instance Attribute Details

#last_answerObject (readonly)

Returns the value of attribute last_answer.



224
225
226
# File 'lib/ankit/challenge.rb', line 224

def last_answer
  @last_answer
end

#progressObject (readonly)

Returns the value of attribute progress.



224
225
226
# File 'lib/ankit/challenge.rb', line 224

def progress
  @progress
end

Instance Method Details

#ask(msg = "", type = :ask) ⇒ Object



264
265
266
# File 'lib/ankit/challenge.rb', line 264

def ask(msg="", type=:ask)
  line.ask(message_for(msg, type)) { |q| q.readline = true }
end

#erase_lastObject



238
239
240
# File 'lib/ankit/challenge.rb', line 238

def erase_last
  runtime.stdout.print("\033[1A")
end

#keep_pumping_until(&block) ⇒ Object



230
231
232
233
234
235
# File 'lib/ankit/challenge.rb', line 230

def keep_pumping_until(&block)
  state = self
  until block.call(state)
    state = state.pump
  end
end

#lineObject



270
# File 'lib/ankit/challenge.rb', line 270

def line; progress.runtime.line; end

#over?Boolean

Returns:

  • (Boolean)


268
# File 'lib/ankit/challenge.rb', line 268

def over?; false; end

#runtimeObject



269
# File 'lib/ankit/challenge.rb', line 269

def runtime; progress.runtime; end

#say(msg, type = :progress) ⇒ Object



242
243
244
# File 'lib/ankit/challenge.rb', line 242

def say(msg, type=:progress)
  line.say(message_for(msg, type))
end

#sessionObject



271
# File 'lib/ankit/challenge.rb', line 271

def session; progress.session; end

#show_and_ask_enter(msg, type) ⇒ Object



260
261
262
# File 'lib/ankit/challenge.rb', line 260

def show_and_ask_enter(msg, type)
  line.ask(message_for(msg, type) + " ") { |q| q.readline = true }
end

#show_breaking_statusObject



256
257
258
# File 'lib/ankit/challenge.rb', line 256

def show_breaking_status
  show_summary_header
end

#show_summary_headerObject



246
247
248
249
250
251
252
253
254
# File 'lib/ankit/challenge.rb', line 246

def show_summary_header
  hitrate = sprintf("%.1f", self.session.hitrate)
  status  = ["P:#{self.session.limit_reach}/#{self.session.limit}",
             "H:#{hitrate}",
             "M:" + self.session.maturity_triple.map(&:to_s).join(","),
             "R:#{self.progress.this_round.to_s}"
             ]
  line.say(status.join(" "))
end