Class: Rufio::DirectoryListing
- Inherits:
-
Object
- Object
- Rufio::DirectoryListing
- Defined in:
- lib/rufio/directory_listing.rb
Instance Attribute Summary collapse
-
#current_path ⇒ Object
readonly
Returns the value of attribute current_path.
-
#start_directory ⇒ Object
readonly
Returns the value of attribute start_directory.
Instance Method Summary collapse
-
#initialize(path = Dir.pwd) ⇒ DirectoryListing
constructor
A new instance of DirectoryListing.
- #list_entries ⇒ Object
- #navigate_to(target) ⇒ Object
- #navigate_to_parent ⇒ Object
- #navigate_to_path(path) ⇒ Object
- #refresh ⇒ Object
Constructor Details
#initialize(path = Dir.pwd) ⇒ DirectoryListing
Returns a new instance of DirectoryListing.
9 10 11 12 13 14 |
# File 'lib/rufio/directory_listing.rb', line 9 def initialize(path = Dir.pwd) @current_path = File.(path) @start_directory = @current_path # 起動時のディレクトリを保存 @entries = [] refresh end |
Instance Attribute Details
#current_path ⇒ Object (readonly)
Returns the value of attribute current_path.
7 8 9 |
# File 'lib/rufio/directory_listing.rb', line 7 def current_path @current_path end |
#start_directory ⇒ Object (readonly)
Returns the value of attribute start_directory.
7 8 9 |
# File 'lib/rufio/directory_listing.rb', line 7 def start_directory @start_directory end |
Instance Method Details
#list_entries ⇒ Object
16 17 18 |
# File 'lib/rufio/directory_listing.rb', line 16 def list_entries @entries end |
#navigate_to(target) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rufio/directory_listing.rb', line 35 def navigate_to(target) return false if target.nil? || target.empty? new_path = File.join(@current_path, target) if File.directory?(new_path) && File.readable?(new_path) @current_path = File.(new_path) refresh true else false end end |
#navigate_to_parent ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rufio/directory_listing.rb', line 49 def navigate_to_parent parent_path = File.dirname(@current_path) # 同じパスの場合は移動しない(ルートディレクトリに到達) return false if parent_path == @current_path if File.directory?(parent_path) && File.readable?(parent_path) @current_path = parent_path refresh true else false end end |
#navigate_to_path(path) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rufio/directory_listing.rb', line 64 def navigate_to_path(path) return false if path.nil? || path.empty? = File.(path) if File.directory?() && File.readable?() @current_path = refresh true else false end end |
#refresh ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rufio/directory_listing.rb', line 20 def refresh return unless File.directory?(@current_path) @entries = [] # NativeScannerが利用可能な場合は使用 if use_native_scanner? scan_with_native_scanner else scan_with_ruby end sort_entries! end |