Sha256: 28e4d808e3fa17fada4d62309345aa0e34e7273bbeca4d35149040dc3bf3b935

Contents?: true

Size: 1.04 KB

Versions: 57

Compression:

Stored size: 1.04 KB

Contents

# 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
  
  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
  
  public
    
    # Tells if an importer has been found for this extension
    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
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
tracksperanto-1.7.3 lib/tracksperanto/format_detector.rb
tracksperanto-1.7.2 lib/tracksperanto/format_detector.rb
tracksperanto-1.7.1 lib/tracksperanto/format_detector.rb
tracksperanto-1.7.0 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.9 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.8 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.7 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.6 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.5 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.4 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.3 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.2 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.1 lib/tracksperanto/format_detector.rb
tracksperanto-1.6.0 lib/tracksperanto/format_detector.rb
tracksperanto-1.5.7 lib/tracksperanto/format_detector.rb
tracksperanto-1.5.6 lib/tracksperanto/format_detector.rb
tracksperanto-1.5.5 lib/tracksperanto/format_detector.rb