Class: NeocitiesRed::Services::File::List
- Inherits:
-
Object
- Object
- NeocitiesRed::Services::File::List
- Defined in:
- lib/neocities_red/services/file/list.rb
Overview
Lists files on the remote Neocities site.
Supports both a simple list mode and a detailed table mode with file size, SHA1 hash, and last-updated timestamp.
Instance Method Summary collapse
-
#initialize(client, path, detail, display: NeocitiesRed::CliDisplay.new) ⇒ List
constructor
A new instance of List.
-
#list ⇒ Array<Hash>
Returns the raw list of remote files.
-
#show ⇒ Array<Hash>
Returns the file list, optionally rendered as a detailed table.
Constructor Details
#initialize(client, path, detail, display: NeocitiesRed::CliDisplay.new) ⇒ List
Returns a new instance of List.
31 32 33 34 35 36 37 |
# File 'lib/neocities_red/services/file/list.rb', line 31 def initialize(client, path, detail, display: NeocitiesRed::CliDisplay.new) @client = client @path = path @detail = detail || false @display = display @pastel = Pastel.new(eachline: "\n") end |
Instance Method Details
#list ⇒ Array<Hash>
Returns the raw list of remote files.
44 45 46 |
# File 'lib/neocities_red/services/file/list.rb', line 44 def list files_from_response end |
#show ⇒ Array<Hash>
Returns the file list, optionally rendered as a detailed table.
In detail mode, displays a colored table with Path, Size, SHA1 Hash, and Updated columns. Directories are shown in blue, files in green.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/neocities_red/services/file/list.rb', line 55 def show files = files_from_response return files unless @detail out = [ [@pastel.bold("Path"), @pastel.bold("Size"), @pastel.bold("sha1_Hash"), @pastel.bold("Updated")] ] 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 @display.display_list_table(TTY::Table.new(out)) files end |