Class: NeocitiesRed::Services::FileList
- Inherits:
-
Object
- Object
- NeocitiesRed::Services::FileList
- Defined in:
- lib/neocities_red/services/file_list.rb
Instance Method Summary collapse
-
#initialize(client, path, detail) ⇒ FileList
constructor
A new instance of FileList.
- #list ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize(client, path, detail) ⇒ FileList
Returns a new instance of FileList.
10 11 12 13 14 15 |
# File 'lib/neocities_red/services/file_list.rb', line 10 def initialize(client, path, detail) @client = client @path = path @detail = detail || false @pastel = Pastel.new(eachline: "\n") end |
Instance Method Details
#list ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/neocities_red/services/file_list.rb', line 17 def list resp = @client.list(@path) display_error_and_exit(resp) if resp[:result] == "error" resp[:files] end |
#show ⇒ Object
25 26 27 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 |
# File 'lib/neocities_red/services/file_list.rb', line 25 def show resp = @client.list(@path) display_error_and_exit(resp) if resp[:result] == "error" if @detail out = [ [@pastel.bold("Path"), @pastel.bold("Size"), @pastel.bold("sha1_Hash"), @pastel.bold("Updated")] ] resp[:files].each do |file| out.push([ @pastel.send(file[:is_directory] ? :blue : :green).bold(file[:path]), file[:size] || "", file[:sha1_hash], Time.parse(file[:updated_at]).localtime ]) end puts TTY::Table.new(out) end resp[:files].map do |file| @pastel.send(file[:is_directory] ? :blue : :green).bold(file[:path]) end resp[:files] end |