class AdventureRL::FileGroup

This is an abstract class, which is inherited by

Public Class Methods

new(settings_arg) click to toggle source

Initialize with either a path to a YAML settings file as a String, or a Hash containing your settings.

# File lib/AdventureRL/FileGroup.rb, line 10
def initialize settings_arg
  settings   = Settings.new settings_arg
  @settings  = get_settings_with settings
  @name      = @settings.get :name
  @directory = get_directory_from_settings @settings
  validate_directory @directory
  @files     = get_file_paths
end

Public Instance Methods

get_directory()
Alias for: get_file_directory
get_file(index) click to toggle source

Returns the filepath at index index.

# File lib/AdventureRL/FileGroup.rb, line 38
def get_file index
  return @files[index]
end
get_file_directory() click to toggle source

Returns the set directory of files.

# File lib/AdventureRL/FileGroup.rb, line 43
def get_file_directory
  return @directory
end
Also aliased as: get_directory
get_files() click to toggle source

Returns an Array of the filepaths.

# File lib/AdventureRL/FileGroup.rb, line 33
def get_files
  return @files
end
get_name() click to toggle source

Returns the Clip's name.

# File lib/AdventureRL/FileGroup.rb, line 28
def get_name
  return @name
end
get_settings(*keys) click to toggle source

Returns the settings as AdventureRL::Settings, unless *keys are given, then it returns the value of @settings.get(*keys).

# File lib/AdventureRL/FileGroup.rb, line 22
def get_settings *keys
  return @settings  if (keys.empty?)
  return @settings.get(*keys)
end
has_file_index?(index) click to toggle source

Returns true if index file exists.

# File lib/AdventureRL/FileGroup.rb, line 49
def has_file_index? index
  return index < @files.size && index >= 0
end
Also aliased as: has_index?
has_index?(index)
Alias for: has_file_index?

Private Instance Methods

get_default_settings() click to toggle source

This method should be overwritten by the child class, and return their specific INTERNAL_DEFAULT_SETTINGS.

# File lib/AdventureRL/FileGroup.rb, line 62
def get_default_settings
  return {}
end
get_directory_from_settings(settings = @settings) click to toggle source
# File lib/AdventureRL/FileGroup.rb, line 66
def get_directory_from_settings settings = @settings
  directory = settings.get(:directory)
  directory = directory.to_path  if (directory.is_a? Pathname)
  error(
    "`:directory' key must be given in settings hash to #new."
  )  unless (directory)
  return Pathname.new File.join(self.class.get_root_directory, directory)
end
get_file_paths() click to toggle source
# File lib/AdventureRL/FileGroup.rb, line 79
def get_file_paths
  return sort_files(get_directory.each_child.select do |file|
    next false  unless (file.file?)
    next file.basename.to_path.match? get_filename_regex
  end)
end
get_filename_regex() click to toggle source

This method should be overwritten by the child class. It should return the regex which must match the filenames.

# File lib/AdventureRL/FileGroup.rb, line 96
def get_filename_regex
  return /\A.+\..+\z/
end
get_settings_with(custom_settings) click to toggle source
# File lib/AdventureRL/FileGroup.rb, line 56
def get_settings_with custom_settings
  return get_default_settings.merge custom_settings
end
sort_files(files) click to toggle source
# File lib/AdventureRL/FileGroup.rb, line 86
def sort_files files
  return files.sort do |file_one, file_two|
    number_one = file_one.basename.to_path.match(/\A(\d+)\..+\z/)[1].to_i
    number_two = file_two.basename.to_path.match(/\A(\d+)\..+\z/)[1].to_i
    next number_one <=> number_two
  end
end
validate_directory(directory = get_directory) click to toggle source
# File lib/AdventureRL/FileGroup.rb, line 75
def validate_directory directory = get_directory
  error_no_directory directory  unless (directory_exists? directory)
end