Class: Formatters::PollingFormatter
- Inherits:
-
Object
- Object
- Formatters::PollingFormatter
- Defined in:
- lib/tramtracker/formatters/polling_formatter.rb
Constant Summary collapse
- KILL_LINE_CHAR =
"\x1B[K"- CURSOR_UP_CHAR =
"\x1B[A"
Instance Method Summary collapse
-
#initialize(tramtracker) ⇒ PollingFormatter
constructor
A new instance of PollingFormatter.
- #report ⇒ Object
Constructor Details
#initialize(tramtracker) ⇒ PollingFormatter
Returns a new instance of PollingFormatter.
7 8 9 10 11 |
# File 'lib/tramtracker/formatters/polling_formatter.rb', line 7 def initialize(tramtracker) @tramtracker = tramtracker @delay_interval = 15 @max_iterations = 60 end |
Instance Method Details
#report ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tramtracker/formatters/polling_formatter.rb', line 13 def report puts Time.now.strftime "[%H:%M:%S] Stop #{@tramtracker.stop_id}" puts "Retrieving tram information..." last_results_count = 0 @max_iterations.times do |iteration| results = @tramtracker.get clear(last_results_count + 2) last_results_count = results.count puts Time.now.strftime "[%H:%M:%S] Stop #{@tramtracker.stop_id}" results.each do |tram| printf "Route %3s arriving in %2s minutes\n", tram[:route], tram[:minutes] end delay @delay_interval end end |