Class: LanguageSniffer::Pathname
- Inherits:
-
Object
- Object
- LanguageSniffer::Pathname
- Defined in:
- lib/language_sniffer/pathname.rb
Overview
Similar to ::Pathname, LanguageSniffer::Pathname wraps a path string and provides helpful query methods. Its useful when you only have a filename but not a blob and need to figure out the language of the file.
Instance Method Summary collapse
-
#basename ⇒ Object
Public: Get the basename of the path.
- #eql?(other) ⇒ Boolean (also: #==)
-
#extname ⇒ Object
Public: Get the extname of the path.
-
#initialize(path) ⇒ Pathname
constructor
Public: Initialize a Pathname.
-
#language ⇒ Object
Public: Get the language of the path.
-
#to_s ⇒ Object
Public: Return self as String.
Constructor Details
#initialize(path) ⇒ Pathname
Public: Initialize a Pathname
path - A filename String. The file may or maybe actually exist.
Returns a Pathname.
13 14 15 |
# File 'lib/language_sniffer/pathname.rb', line 13 def initialize(path) @path = path end |
Instance Method Details
#basename ⇒ Object
25 26 27 |
# File 'lib/language_sniffer/pathname.rb', line 25 def basename File.basename(@path) end |
#eql?(other) ⇒ Boolean Also known as: ==
66 67 68 |
# File 'lib/language_sniffer/pathname.rb', line 66 def eql?(other) other.is_a?(self.class) && @path == other.to_s end |
#extname ⇒ Object
40 41 42 |
# File 'lib/language_sniffer/pathname.rb', line 40 def extname File.extname(@path) end |
#language ⇒ Object
55 56 57 |
# File 'lib/language_sniffer/pathname.rb', line 55 def language @language ||= Language.find_by_filename(@path) end |
#to_s ⇒ Object
Public: Return self as String
Returns a String
62 63 64 |
# File 'lib/language_sniffer/pathname.rb', line 62 def to_s @path.dup end |