Class: DataFile::Detector
- Inherits:
-
Object
- Object
- DataFile::Detector
- Defined in:
- lib/data_file/detector.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #encoding ⇒ Object
-
#initialize(file) ⇒ Detector
constructor
A new instance of Detector.
- #mime_type ⇒ Object
- #text? ⇒ Boolean
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
#file ⇒ Object (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
#encoding ⇒ Object
15 16 17 |
# File 'lib/data_file/detector.rb', line 15 def encoding file.external_encoding.name end |
#mime_type ⇒ Object
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
11 12 13 |
# File 'lib/data_file/detector.rb', line 11 def text? mime_type =~ /text\/(plain|csv|comma-separated-values)/ end |