Module: Shutwork::Command::Display

Included in:
Base
Defined in:
lib/shutwork/command/display.rb

Instance Method Summary collapse

Instance Method Details

#display_account(item) ⇒ Object



4
5
6
# File 'lib/shutwork/command/display.rb', line 4

def  item
  puts ("%10s  %s" % [item["account_id"], item["name"]])
end

#display_file(item) ⇒ Object



21
22
23
24
25
26
27
# 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) ⇒ Object



12
13
14
15
16
17
18
19
# 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) ⇒ Object



8
9
10
# File 'lib/shutwork/command/display.rb', line 8

def display_room item
  puts ("%10s  %s" % [item["room_id"], item["name"]])
end

#format_datetime(x) ⇒ Object



29
30
31
# File 'lib/shutwork/command/display.rb', line 29

def format_datetime x
  Time.at(x).to_s
end

#format_filesize(x) ⇒ Object



33
34
35
# File 'lib/shutwork/command/display.rb', line 33

def format_filesize x
  to_filesize_human x
end

#to_filesize_human(x) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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