Class: MediaOrganizer::Filescanner
- Inherits:
-
Object
- Object
- MediaOrganizer::Filescanner
- Defined in:
- lib/filescanner.rb
Constant Summary
Constants included from Music
Constants included from Image
Instance Attribute Summary collapse
-
#root_nodes ⇒ Object
readonly
Returns the value of attribute root_nodes.
-
#source_list ⇒ Object
Returns the value of attribute source_list.
Instance Method Summary collapse
-
#add_root(dir_uri) ⇒ Object
alternative run mode.
-
#initialize ⇒ Filescanner
constructor
A new instance of Filescanner.
-
#multiscan(args = {}) ⇒ Object
multiscan(): scans multiple directories added to @root_nodes using the add_root() method.
-
#open(uri = '', args = {}) ⇒ Object
Filescanner.open(String, {}): scans directory tree for media files, starting at String specified in first argument.
Methods included from Music
availableMetadata, get_music_data, music?, supported_filetypes, writeMetadata
Methods included from Image
get_jpeg_data, get_tiff_data, image?, supported_filetypes
Constructor Details
#initialize ⇒ Filescanner
Returns a new instance of Filescanner.
16 17 18 19 |
# File 'lib/filescanner.rb', line 16 def initialize @root_nodes = [] @source_list = [] end |
Instance Attribute Details
#root_nodes ⇒ Object (readonly)
Returns the value of attribute root_nodes.
13 14 15 |
# File 'lib/filescanner.rb', line 13 def root_nodes @root_nodes end |
#source_list ⇒ Object
Returns the value of attribute source_list.
14 15 16 |
# File 'lib/filescanner.rb', line 14 def source_list @source_list end |
Instance Method Details
#add_root(dir_uri) ⇒ Object
alternative run mode. Add multiple “root” directories to scan at once
64 65 66 67 68 69 70 |
# File 'lib/filescanner.rb', line 64 def add_root(dir_uri) validate_uri(dir_uri) @root_nodes << dir_uri rescue StandardError => e puts "Warning: #{e.}" return false end |
#multiscan(args = {}) ⇒ Object
multiscan(): scans multiple directories added to @root_nodes using the add_root() method.
Inputs
Required
none
Optional
(1) Arguments Hash: *:mode => (:single, :multiple) *:music => (true, false) – if true, music files will be included in the scan.
Set to false to exclude music files. Defaults to true
*:image => (true, false) – if true, image files will be included in the scan.
Set to false to exclude image files. Defaults to true
Outputs
Array of strings, where each string is a file URI for a music or image file.
93 94 95 96 97 98 |
# File 'lib/filescanner.rb', line 93 def multiscan(args = {}) @root_nodes.each do |uri| open(uri, args) end @source_list end |
#open(uri = '', args = {}) ⇒ Object
Filescanner.open(String, {}): scans directory tree for media files, starting at String specified in first argument.
Inputs
Required
(1) String: String containing the URI of the top of the directory tree to scan
Optional
(2) Arguments Hash: *:mode => (:single) – if set to :single, only the given URI will be scanned. Subdirectories will be ignored. *:music => (true, false) – if true, music files will be included in the scan.
Set to false to exclude music files. Defaults to true
*:image => (true, false) – if true, image files will be included in the scan.
Set to false to exclude image files. Defaults to true
Outputs
Returns array of strings, where each string is a file URI for a music or image file.
Usage Example
Filescanner.open(“/absolute/path/for/top/of/directory/tree”)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/filescanner.rb', line 45 def open(uri = '', args = {}) include_images = true unless args[:image] == false include_music = true unless args[:music] == false files = load_files(uri, args[:mode]) files.each do |f| if (Music.music?(f) && include_music) || (Image.image?(f) && include_images) @source_list << f end end return @source_list rescue StandardError => e puts "Warning: #{e.}" return false end |