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.



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



30
31
32
# File 'lib/git_stats/git_data/blob.rb', line 30

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

#binary?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/git_stats/git_data/blob.rb', line 24

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



16
17
18
# File 'lib/git_stats/git_data/blob.rb', line 16

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

#extensionObject



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

def extension
  @extension ||= 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 #{sha} | wc -l").to_i
end