Method: Argos::Ascii.type
- Defined in:
- lib/argos/ascii.rb
.type(filename) ⇒ String
Detect Argos ASCII filetype (“ds” or “diag” or nil)
“ds”|“diag”
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/argos/ascii.rb', line 9 def self.type filename if File.file? filename # Avoid invalid byte sequence in UTF-8 (ArgumentError) firstline = File.open(filename, :encoding => "iso-8859-1") {|f| f.readline} else firstline = filename end case firstline when Argos::Ds::START_REGEX, Argos::Ds::START_REGEX_LEGACY "ds" when Argos::Diag::START_REGEX "diag" when "", nil raise ArgumentError, "Not a file or empty string: #{filename}" else nil end end |