class Verku::SourceList
Constants
- EXTENSIONS
List of recognized extensions.
- IGNORE_DIR
List of directories that should be skipped.
- IGNORE_FILES
Files that should be skipped.
Attributes
root_dir[R]
source[R]
Public Class Methods
new(root_dir)
click to toggle source
# File lib/verku/source_list.rb, line 18 def initialize(root_dir) @root_dir = root_dir @source = root_dir.join('text') # @source = root_dir end
Public Instance Methods
chapter_files(entry)
click to toggle source
# File lib/verku/source_list.rb, line 37 def chapter_files(entry) # Chapters can be files outside a directory. if File.file?(entry) [entry] else # markdown,mkdown,mkdn,mkd,md Dir["#{entry}/**/*.{#{EXTENSIONS.join(",")}}"].sort end end
each_chapter(&block)
click to toggle source
# File lib/verku/source_list.rb, line 26 def each_chapter(&block) files_grouped_by_chapter.each(&block) end
entries()
click to toggle source
Return a list of all recognized files.
# File lib/verku/source_list.rb, line 48 def entries Dir.entries(source).sort.each_with_object([]) do |entry, buffer| buffer << source.join(entry) if valid_entry?(entry) end end
files_grouped_by_chapter()
click to toggle source
# File lib/verku/source_list.rb, line 30 def files_grouped_by_chapter entries.each_with_object([]) do |entry, buffer| files = chapter_files(entry) buffer << files unless files.empty? end end
valid_directory?(entry)
click to toggle source
Check if path is a valid directory.
# File lib/verku/source_list.rb, line 62 def valid_directory?(entry) File.directory?(source.join(entry)) && !IGNORE_DIR.include?(File.basename(entry)) end
valid_entry?(entry)
click to toggle source
Check if path is a valid entry. Files/directories that start with a dot or underscore will be skipped.
# File lib/verku/source_list.rb, line 56 def valid_entry?(entry) entry !~ /^(\.|_)/ && (valid_directory?(entry) || valid_file?(entry)) end
valid_file?(entry)
click to toggle source
Check if path is a valid file.
# File lib/verku/source_list.rb, line 68 def valid_file?(entry) ext = File.extname(entry).gsub(/\./, "").downcase File.file?(source.join(entry)) && EXTENSIONS.include?(ext) && entry !~ IGNORE_FILES end