Class: GitStats::GitData::Blob

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspector

#inspect, #pretty_print, #to_s

Methods included from HashInitializable

#initialize

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/git_stats/git_data/blob.rb', line 12

def filename
  @filename
end

#repoObject (readonly)

Returns the value of attribute repo.



12
13
14
# File 'lib/git_stats/git_data/blob.rb', line 12

def repo
  @repo
end

#shaObject (readonly)

Returns the value of attribute sha.



12
13
14
# File 'lib/git_stats/git_data/blob.rb', line 12

def sha
  @sha
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
# File 'lib/git_stats/git_data/blob.rb', line 32

def ==(other)
  [repo, sha, filename] == [other.repo, other.sha, other.filename]
end

#binary?Boolean

Returns:

  • (Boolean)


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

def binary?
  repo.run("git cat-file blob #{sha} | grep -m 1 '^'").dup
      .force_encoding('ISO-8859-1').encode('utf-8', replace: nil)
      .include?('Binary file')
end

#contentObject



18
19
20
# File 'lib/git_stats/git_data/blob.rb', line 18

def content
  @content ||= repo.run("git cat-file blob #{sha}")
end

#extensionObject



22
23
24
# File 'lib/git_stats/git_data/blob.rb', line 22

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

#lines_countObject



14
15
16
# File 'lib/git_stats/git_data/blob.rb', line 14

def lines_count
  @lines_count ||= binary? ? 0 : repo.run("git cat-file blob #{sha} | wc -l").to_i
end