Class: TarkinCommands
- Inherits:
-
Object
- Object
- TarkinCommands
- Defined in:
- lib/tarkin_commands.rb
Instance Method Summary collapse
- #cat(pwd) ⇒ Object
-
#dirs(dir) ⇒ Object
Returns only dirs.
- #find(term) ⇒ Object
-
#initialize(client) ⇒ TarkinCommands
constructor
A new instance of TarkinCommands.
-
#items(dir) ⇒ Object
Returns items only in given directory.
- #ls(path, long) ⇒ Object
Constructor Details
#initialize(client) ⇒ TarkinCommands
Returns a new instance of TarkinCommands.
20 21 22 |
# File 'lib/tarkin_commands.rb', line 20 def initialize(client) @client = client end |
Instance Method Details
#cat(pwd) ⇒ Object
24 25 26 |
# File 'lib/tarkin_commands.rb', line 24 def cat(pwd) puts @client.password(pwd)[:password] end |
#dirs(dir) ⇒ Object
Returns only dirs
88 89 90 |
# File 'lib/tarkin_commands.rb', line 88 def dirs(dir) @client.ls(URI::encode(dir))[:directories] end |
#find(term) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tarkin_commands.rb', line 71 def find(term) list = @client.find(term).sort_by {|x| x[:label]} list.each do |thing| unless thing[:redirect_to].include?('#') puts thing[:label].blue else puts thing[:label].white end end end |
#items(dir) ⇒ Object
Returns items only in given directory
83 84 85 |
# File 'lib/tarkin_commands.rb', line 83 def items(dir) @client.ls(URI::encode(dir))[:items] end |
#ls(path, long) ⇒ Object
28 29 30 31 32 33 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 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tarkin_commands.rb', line 28 def ls(path, long) list = @client.ls(URI::encode(path)) if long all = (list[:directories].collect{|dir| ["#{dir[:name]}/", 'blue', dir[:created_at], dir[:updated_at], dir[:description]]} + list[:items].collect{|item| [item[:username], 'white', item[:created_at], item[:updated_at], item[:description]]}).sort unless all.empty? cols = 3 len = max_len(all) table border: false do all.each do |thing| row do column thing[2].to_time.strftime('%Y-%m-%d %T'), width: 22 column thing[3].to_time.strftime('%Y-%m-%d %T'), width: 22 column thing[0], width: len+2, color: thing[1] chars_to_end = HighLine::SystemExtensions.terminal_size.first - 22*2 - (len+6) column thing[4].truncate(chars_to_end), width: chars_to_end end end end end else # all contains directories and users, a list of list - item and display color: [[dir1, 'blue'], [user1, 'white']] # reversed because we will be poping the table all = (list[:directories].collect{|dir| ["#{dir[:name]}/", 'blue']} + list[:items].collect{|item| [item[:username], 'white']}).sort.reverse unless all.empty? cols = columns(all) rows = all.count / cols + ( all.count % cols == 0 ? 0 : 1 ) len = max_len(all) table border: false do rows.times do row do cols.times do item = all.pop column(item && item.first , width: len, color: item && item.last) end end end end end end end |