Class: DataFile::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/data_file/detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Detector

Returns a new instance of Detector.



7
8
9
# File 'lib/data_file/detector.rb', line 7

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/data_file/detector.rb', line 5

def file
  @file
end

Instance Method Details

#encodingObject



15
16
17
# File 'lib/data_file/detector.rb', line 15

def encoding
  file.external_encoding.name
end

#mime_typeObject



19
20
21
# File 'lib/data_file/detector.rb', line 19

def mime_type
  MIME::Types.type_for(file.path).first.content_type
end

#text?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/data_file/detector.rb', line 11

def text?
  mime_type =~ /text\/(plain|csv|comma-separated-values)/
end