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.



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

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.



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

def last_answer
  @last_answer
end

#progressObject (readonly)

Returns the value of attribute progress.



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

def progress
  @progress
end

Instance Method Details

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



262
263
264
# File 'lib/ankit/challenge.rb', line 262

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

#erase_lastObject



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

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

#keep_pumping_until(&block) ⇒ Object



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

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

#lineObject



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

def line; progress.runtime.line; end

#over?Boolean

Returns:

  • (Boolean)


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

def over?; false; end

#runtimeObject



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

def runtime; progress.runtime; end

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



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

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

#sessionObject



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

def session; progress.session; end

#show_and_ask_enter(msg, type) ⇒ Object



258
259
260
# File 'lib/ankit/challenge.rb', line 258

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

#show_breaking_statusObject



254
255
256
# File 'lib/ankit/challenge.rb', line 254

def show_breaking_status
  show_summary_header
end

#show_summary_headerObject



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

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