Class: GitStats::GitData::Blob

Inherits:
Object
  • Object
show all
Includes:
HashInitializable
Defined in:
lib/git_stats/git_data/blob.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashInitializable

#initialize

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename


10
11
12
# File 'lib/git_stats/git_data/blob.rb', line 10

def filename
  @filename
end

#repoObject (readonly)

Returns the value of attribute repo


10
11
12
# File 'lib/git_stats/git_data/blob.rb', line 10

def repo
  @repo
end

#shaObject (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

Returns:

  • (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

#contentObject


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

#extensionObject


20
21
22
# File 'lib/git_stats/git_data/blob.rb', line 20

def extension
  @ext ||= File.extname(filename)
end

#lines_countObject


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_sObject


28
29
30
# File 'lib/git_stats/git_data/blob.rb', line 28

def to_s
  "#{self.class} #@sha #@filename"
end