module Shutwork::Command::Display
Public Instance Methods
display_account(item)
click to toggle source
# File lib/shutwork/command/display.rb, line 4 def display_account item puts ("%10s %s" % [item["account_id"], item["name"]]) end
display_file(item)
click to toggle source
# File lib/shutwork/command/display.rb, line 21 def display_file item puts ("%s %6s %s" % [ format_datetime(item["upload_time"]), format_filesize(item["filesize"]), item["filename"]] ) end
display_message(item)
click to toggle source
# File lib/shutwork/command/display.rb, line 12 def display_message item puts "----------------" puts ("%s %s" % [ format_datetime(item["send_time"]), item.dig("account", "name") ]) puts item["body"] end
display_room(item)
click to toggle source
# File lib/shutwork/command/display.rb, line 8 def display_room item puts ("%10s %s" % [item["room_id"], item["name"]]) end
format_datetime(x)
click to toggle source
# File lib/shutwork/command/display.rb, line 29 def format_datetime x Time.at(x).to_s end
format_filesize(x)
click to toggle source
# File lib/shutwork/command/display.rb, line 33 def format_filesize x to_filesize_human x end
to_filesize_human(x)
click to toggle source
# File lib/shutwork/command/display.rb, line 37 def to_filesize_human x x = %w(KB MB GB TB).inject([x.to_f, 'B']) do |acc, u| v = acc.first / 1024 if v.round(2) < 0.90 acc else [v, u] end end if x.first >= 10.0 || x.last == 'B' "%.0f%s" % x else "%.1f%s" % x end end