class Tracksperanto::FormatDetector

Finds a suitable importer for the chosen file path. Or at least tries to, based on the file extension. Will then examine all the importers and ask them if they can handle the specified file

Public Class Methods

new(with_path) click to toggle source
# File lib/tracksperanto/format_detector.rb, line 5
def initialize(with_path)
  perform_detection(with_path)
  freeze
end

Public Instance Methods

auto_size?() click to toggle source

Tells if comp size needs to be provided

# File lib/tracksperanto/format_detector.rb, line 21
def auto_size?
  match? ? importer_klass.autodetects_size? : false
end
human_importer_name() click to toggle source

Returns the human name of the importer

# File lib/tracksperanto/format_detector.rb, line 26
def human_importer_name
  match? ? importer_klass.human_name : "Unknown format"
end
importer_klass() click to toggle source

Returns the importer if there is one

# File lib/tracksperanto/format_detector.rb, line 16
def importer_klass
  @importer_klass
end
match?() click to toggle source

Tells if an importer has been found for this file

# File lib/tracksperanto/format_detector.rb, line 11
def match?
  !!@importer_klass
end

Private Instance Methods

perform_detection(for_path) click to toggle source
# File lib/tracksperanto/format_detector.rb, line 32
def perform_detection(for_path)
  return unless (for_path && !for_path.to_s.empty?)
  ext = File.extname(for_path.downcase)
  @importer_klass = Tracksperanto.importers.find{ |i| i.distinct_file_ext == ext }
end