Sha256: ba14be02e51a474fe5fa853d1d9277aecf6ff2ecc3e000e1b12f4bb7cda5991a

Contents?: true

Size: 1 KB

Versions: 36

Compression:

Stored size: 1 KB

Contents

# -*- encoding : utf-8 -*-
# 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
class Tracksperanto::FormatDetector
  
  def initialize(with_path)
    perform_detection(with_path)
    freeze
  end
  
  # Tells if an importer has been found for this file
  def match?
    !!@importer_klass
  end
  
  # Returns the importer if there is one
  def importer_klass
    @importer_klass
  end
  
  # Tells if comp size needs to be provided
  def auto_size?
    match? ? importer_klass.autodetects_size? : false
  end
  
  # Returns the human name of the importer
  def human_importer_name
    match? ? importer_klass.human_name : "Unknown format"
  end
  
  private

  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
  
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
tracksperanto-3.5.9 lib/tracksperanto/format_detector.rb
tracksperanto-3.5.8 lib/tracksperanto/format_detector.rb
tracksperanto-3.5.7 lib/tracksperanto/format_detector.rb
tracksperanto-3.5.6 lib/tracksperanto/format_detector.rb
tracksperanto-3.5.5 lib/tracksperanto/format_detector.rb
tracksperanto-3.5.4 lib/tracksperanto/format_detector.rb
tracksperanto-3.5.2 lib/tracksperanto/format_detector.rb
tracksperanto-3.5.1 lib/tracksperanto/format_detector.rb
tracksperanto-3.5.0 lib/tracksperanto/format_detector.rb
tracksperanto-3.4.1 lib/tracksperanto/format_detector.rb
tracksperanto-3.4.0 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.13 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.12 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.11 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.10 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.9 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.8 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.7 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.6 lib/tracksperanto/format_detector.rb
tracksperanto-3.3.0.pre lib/tracksperanto/format_detector.rb