class Net::FTP::List::Parser
Abstract FTP LIST parser. It really just defines and documents the interface.
Public Class Methods
inherited(klass)
click to toggle source
Automatically add an inheriting parser to the list of known parsers.
Calls superclass method
# File lib/net/ftp/list/parser.rb, line 17 def inherited(klass) super register(klass) end
parse(_raw, **)
click to toggle source
The main parse method. Return false from it if parsing fails (this is cheaper than raising an exception)
# File lib/net/ftp/list/parser.rb, line 23 def parse(_raw, **) false end
parsers()
click to toggle source
Returns registered parsers.
# File lib/net/ftp/list/parser.rb, line 7 def parsers @parsers ||= [] end
register(parser)
click to toggle source
Manuall register a parser.
# File lib/net/ftp/list/parser.rb, line 12 def register(parser) parsers.push(parser) unless parsers.include?(parser) end
Private Class Methods
emit_entry(raw, **extra)
click to toggle source
Automatically adds the name of the parser class to the server_type field
# File lib/net/ftp/list/parser.rb, line 30 def emit_entry(raw, **extra) Net::FTP::List::Entry.new raw, **extra, server_type: to_s.split('::').pop end
parse_time(str, timezone:, format: nil)
click to toggle source
# File lib/net/ftp/list/parser.rb, line 34 def parse_time(str, timezone:, format: nil) case timezone when :utc (format ? DateTime.strptime(str, format) : DateTime.parse(str)).to_time when :local format ? Time.strptime(str, format) : Time.parse(str) else raise ArgumentError, "invalid timezone #{timezone}, only :utc and :local are allowed" end end