Class: Status

Inherits:
PostCL::Command show all
Defined in:
lib/postcl/command/status.rb

Constant Summary collapse

@@ART =
{
  1 => ["  __________", " |\\    \\    \\", " | \\____\\____\\", " | |      ~~ |", " \\ |         |", "  \\|_________|"],
  2 => ["   __________", "  |       ~~ |", "--|          |--", "  |__________|", "================", "  ( )  ( )  ( )"],
  3 => ["  _________", " |       |_\\", " |PostNL    \\___", " |              |", "  --( )-----( )-", ""],
  4 => ["   _________H", "  /\\         \\", " /  \\         \\", " |  |    _    |", " |  |[] | | []|", " `-_|   |`|   |"],
}

Constants inherited from PostCL::Command

PostCL::Command::ARG_MATCH

Instance Method Summary collapse

Methods inherited from PostCL::Command

run, validate_args

Constructor Details

#initialize(post) ⇒ Status

Returns a new instance of Status.



9
10
11
# File 'lib/postcl/command/status.rb', line 9

def initialize(post)
  super(post)
end

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/postcl/command/status.rb', line 34

def run
  @args["<barcode>"].zip(@args["<postcode>"]).each do |barcode, postcode|
    spin = TTY::Spinner.new("Zending #{barcode} wordt geladen :spinner...", format: :bouncing_ball, clear: true)
    spin.auto_spin
    begin
      resp = PostCL::API.request(barcode, postcode)
      spin.stop()
    rescue PostCL::API::InvalidRequestError
      spin.stop("Ongeldige aanvraag met barcode: #{barcode} en postcode: #{postcode}")
      next
    end

    @store.prompt_add(resp) unless @store.include?(barcode, postcode) || @args["-n"]

    puts "Status van zending: " + barcode.bold
    stat_banner = Array(6)
    art = @@ART[resp.stat_index]
    (0..5).each do |i|
      stat_banner[i] = art[i].ljust(20, " ") + stat_info(i, resp)
    end
    puts stat_banner.join("\n")
    # puts "Van " + resp.location(:sender).red +
        #  " naar " + resp.location(:receiver).green
    puts
  end
end