Class: Linguist::Blob
- Inherits:
-
Object
- Object
- Linguist::Blob
- Includes:
- BlobHelper
- Defined in:
- lib/linguist/blob.rb
Overview
A Blob is a wrapper around the content of a file to make it quack like a Grit::Blob. It provides the basic interface: ‘name`, `data`, `path` and `size`.
Direct Known Subclasses
Constant Summary
Constants included from BlobHelper
Linguist::BlobHelper::DETECTABLE_TYPES, Linguist::BlobHelper::DocumentationRegexp, Linguist::BlobHelper::MEGABYTE, Linguist::BlobHelper::VendoredRegexp
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Public: Filename.
Instance Method Summary collapse
-
#data ⇒ Object
Public: File contents.
-
#extension ⇒ Object
Public: Get file extension.
-
#extensions ⇒ Object
Public: Return an array of the file extensions.
-
#initialize(path, content, symlink: false) ⇒ Blob
constructor
Public: Initialize a new Blob.
-
#name ⇒ Object
Public: File name.
-
#size ⇒ Object
Public: Get byte size.
-
#symlink? ⇒ Boolean
Public: Is this a symlink?.
Methods included from BlobHelper
#_mime_type, #binary?, #binary_mime_type?, #content_type, #csv?, #detect_encoding, #disposition, #documentation?, #empty?, #encoded_newlines_re, #encoding, #extname, #first_lines, #generated?, #high_ratio_of_long_lines?, #image?, #include_in_language_stats?, #language, #large?, #last_lines, #likely_binary?, #lines, #loc, #mime_type, #pdf?, #ruby_encoding, #safe_to_colorize?, #sloc, #solid?, #text?, #tm_scope, #vendored?, #viewable?
Constructor Details
#initialize(path, content, symlink: false) ⇒ Blob
Public: Initialize a new Blob.
path - A path String (does not necessarily exists on the file system). content - Content of the file. symlink - Whether the file is a symlink.
Returns a Blob.
17 18 19 20 21 |
# File 'lib/linguist/blob.rb', line 17 def initialize(path, content, symlink: false) @path = path @content = content @symlink = symlink end |
Instance Attribute Details
Instance Method Details
#data ⇒ Object
Public: File contents.
Returns a String.
43 44 45 |
# File 'lib/linguist/blob.rb', line 43 def data @content end |
#extension ⇒ Object
Public: Get file extension.
Returns a String.
57 58 59 |
# File 'lib/linguist/blob.rb', line 57 def extension extensions.last || "" end |
#extensions ⇒ Object
Public: Return an array of the file extensions
>> Linguist::Blob.new("app/views/things/index.html.erb").extensions
=> [".html.erb", ".erb"]
Returns an Array
67 68 69 70 71 72 73 |
# File 'lib/linguist/blob.rb', line 67 def extensions _, *segments = name.downcase.split(".", -1) segments.map.with_index do |segment, index| "." + segments[index..-1].join(".") end end |
#name ⇒ Object
Public: File name
Returns a String
36 37 38 |
# File 'lib/linguist/blob.rb', line 36 def name File.basename(@path) end |
#size ⇒ Object
Public: Get byte size
Returns an Integer.
50 51 52 |
# File 'lib/linguist/blob.rb', line 50 def size @content.bytesize end |
#symlink? ⇒ Boolean
Public: Is this a symlink?
Returns true or false.
78 79 80 |
# File 'lib/linguist/blob.rb', line 78 def symlink? @symlink end |