Class: Raval::ListFormatter
- Inherits:
-
Object
- Object
- Raval::ListFormatter
- Defined in:
- lib/raval/list_formatter.rb
Overview
converts a list of objects that describe the contents of a directory and formats them to be valid responses to the LIST or NLST FTP commands.
Instance Method Summary collapse
-
#detailed ⇒ Object
response to the LIST command.
-
#initialize(files) ⇒ ListFormatter
constructor
A new instance of ListFormatter.
-
#short ⇒ Object
response to the NLST command.
Constructor Details
#initialize(files) ⇒ ListFormatter
Returns a new instance of ListFormatter.
7 8 9 |
# File 'lib/raval/list_formatter.rb', line 7 def initialize(files) @files = check_duck_type(files) end |
Instance Method Details
#detailed ⇒ Object
response to the LIST command
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/raval/list_formatter.rb', line 19 def detailed now = Time.now @files.map { |item| directory = item.directory ? 'd' : '-' = item. || 'rwxrwxrwx' owner = item.owner || 'owner' group = item.group || 'group' size = (item.size || 0).to_s.rjust(12) time = (item.time || now).strftime("%b %d %H:%M") name = item.name || "UNKNOWN" "#{directory}#{} 1 #{owner} #{group} #{size} #{time} #{name}" } end |
#short ⇒ Object
response to the NLST command
13 14 15 |
# File 'lib/raval/list_formatter.rb', line 13 def short @files.map(&:name) end |