Class: GitStats::GitData::Blob
- Inherits:
-
Object
- Object
- GitStats::GitData::Blob
- Includes:
- HashInitializable
- Defined in:
- lib/git_stats/git_data/blob.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#sha ⇒ Object
readonly
Returns the value of attribute sha.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #binary? ⇒ Boolean
- #content ⇒ Object
- #extension ⇒ Object
- #lines_count ⇒ Object
- #to_s ⇒ Object
Methods included from HashInitializable
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
10 11 12 |
# File 'lib/git_stats/git_data/blob.rb', line 10 def filename @filename end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
10 11 12 |
# File 'lib/git_stats/git_data/blob.rb', line 10 def repo @repo end |
#sha ⇒ Object (readonly)
Returns the value of attribute sha.
10 11 12 |
# File 'lib/git_stats/git_data/blob.rb', line 10 def sha @sha end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 |
# File 'lib/git_stats/git_data/blob.rb', line 32 def ==(other) [self.repo, self.sha, self.filename] == [other.repo, other.sha, other.filename] end |
#binary? ⇒ Boolean
24 25 26 |
# File 'lib/git_stats/git_data/blob.rb', line 24 def binary? repo.run("git cat-file blob #{self.sha} | grep -m 1 '^'").force_encoding('ISO-8859-1').encode('utf-8', replace: nil) =~ /Binary file/ end |
#content ⇒ Object
16 17 18 |
# File 'lib/git_stats/git_data/blob.rb', line 16 def content @content ||= repo.run("git cat-file blob #{self.sha}") end |
#extension ⇒ Object
20 21 22 |
# File 'lib/git_stats/git_data/blob.rb', line 20 def extension @ext ||= File.extname(filename) end |
#lines_count ⇒ Object
12 13 14 |
# File 'lib/git_stats/git_data/blob.rb', line 12 def lines_count @lines_count ||= binary? ? 0 : repo.run("git cat-file blob #{self.sha} | wc -l").to_i end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/git_stats/git_data/blob.rb', line 28 def to_s "#{self.class} #@sha #@filename" end |