Sha256: e603bb0dc29d85e23f80fb3debc9c860f49a68f948429fde8b092189f6ea9a88

Contents?: true

Size: 856 Bytes

Versions: 11

Compression:

Stored size: 856 Bytes

Contents

# -*- encoding : utf-8 -*-

require 'git_stats/hash_initializable'

module GitStats
  module GitData
    class Blob
      include HashInitializable

      attr_reader :repo, :sha, :filename

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

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

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

      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

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

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

    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
git_stats-1.0.17 lib/git_stats/git_data/blob.rb
git_stats-1.0.16 lib/git_stats/git_data/blob.rb
git_stats-1.0.15 lib/git_stats/git_data/blob.rb
git_stats-1.0.14 lib/git_stats/git_data/blob.rb
git_stats-1.0.13 lib/git_stats/git_data/blob.rb
git_stats-1.0.12 lib/git_stats/git_data/blob.rb
git_stats-1.0.11 lib/git_stats/git_data/blob.rb
git_stats-1.0.10 lib/git_stats/git_data/blob.rb
git_stats-1.0.9 lib/git_stats/git_data/blob.rb
git_stats-1.0.8 lib/git_stats/git_data/blob.rb
git_stats-1.0.7 lib/git_stats/git_data/blob.rb