class Smartdown::Parser::DirectoryInput

Public Class Methods

new(coversheet_path) click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 6
def initialize(coversheet_path)
  @coversheet_path = Pathname.new(coversheet_path.to_s)
end

Public Instance Methods

coversheet() click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 10
def coversheet
  InputFile.new(@coversheet_path)
end
filenames_hash() click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 30
def filenames_hash
  {
    coversheet: coversheet.to_s,
    questions: questions.map(&:to_s),
    outcomes: outcomes.map(&:to_s),
    scenario_sets: scenario_sets.map(&:to_s)
  }
end
outcomes() click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 18
def outcomes
  recursive_files_relatively_renamed("outcomes")
end
questions() click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 14
def questions
  read_dir("questions")
end
scenario_sets() click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 22
def scenario_sets
  read_dir("scenarios")
end
snippets() click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 26
def snippets
  recursive_files_relatively_renamed("snippets")
end

Private Instance Methods

read_dir(dir) click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 40
def read_dir(dir)
  Dir[@coversheet_path.dirname + dir + "*.txt"].map do |filename|
    InputFile.new(filename)
  end
end
recursive_files_relatively_renamed(parent_dir, depth=nil) click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 46
def recursive_files_relatively_renamed(parent_dir, depth=nil)
  parent_path = @coversheet_path.dirname + parent_dir
  return [] unless File.exists?(parent_path)
  
  depth ||= parent_path.each_filename.count
  parent_path.each_child.flat_map do |path| 
    if path.directory?
      recursive_files_relatively_renamed(path, depth)
    else
      InputFile.new(path, relatively_name(path, depth))
    end
  end
end
relatively_name(path, depth) click to toggle source
# File lib/smartdown/parser/directory_input.rb, line 60
def relatively_name(path, depth)
  path.each_filename.to_a[depth..-1].join('/')
end