module GitMeta VERSION = "2.0.0" class Scanner attr_accessor :info REGEX = /(\S+):\s*(.+)$/ def initialize(text) self.info = Hash.new("") text.scan(REGEX) do |k,v| self.info[k] = v end end def ==(comrade) info == comrade.info end end class Hash < ::Hash def to_s inject("") do |result, hash| result += "#{hash[0]}: #{hash[1]}\n" # hash is an array of schema [key, value] end end end class Get attr_accessor :scanner, :key def initialize(sha, key=nil) output = IO.popen("git-cat-file -p #{sha}", 'r') do |git_cat_file| git_cat_file.read end self.scanner = Scanner.new(output) self.key = key end def to_s key ? @scanner.info[key] : @scanner.info.to_s end end end