Module: Onebox::FileTypeFinder

Defined in:
lib/onebox/file_type_finder.rb

Class Method Summary collapse

Class Method Details

.from_file_name(file_name) ⇒ Object


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/onebox/file_type_finder.rb', line 50

def self.from_file_name(file_name)
  lower_name = file_name.downcase  # First check against the known lists of "special" files and extensions.

  return @extensionless_files[lower_name] if @extensionless_files.has_key?(lower_name)

  @long_file_types.each { |extension,type|
    return type if lower_name.end_with?(extension)
  }

  # Otherwise, just split on the last ".",
  # but add one so we don't return the "." itself.
  dot_spot = lower_name.rindex(".")
  return lower_name[(dot_spot+1)..-1] if dot_spot

  # If we couldn't figure it out from the name,
  # let the highlighter figure it out from the content.
  ""
end