class Git::BlameColor::Formatter
Attributes
line_number_width[R]
Public Class Methods
new(author_name_width, line_number_width, options={})
click to toggle source
# File lib/git-blame-color/formatter.rb, line 9 def initialize(author_name_width, line_number_width, options={}) @author_name_width = author_name_width @line_number_width = line_number_width @options = options end
Public Instance Methods
format(commit)
click to toggle source
# File lib/git-blame-color/formatter.rb, line 27 def format(commit) parts = [ color_coded_hash(commit), Rainbow(author_to_s(commit)).blue, Rainbow(timestamp_to_s(commit)).green, Rainbow(line_number_to_s(commit)).black.bright, commit.edited_line ] parts.join(' ') end
long_hashes?()
click to toggle source
# File lib/git-blame-color/formatter.rb, line 15 def long_hashes? !!@options[:long_hashes] end
raw_timestamps?()
click to toggle source
# File lib/git-blame-color/formatter.rb, line 23 def raw_timestamps? !!@options[:raw_timestamps] end
show_boundary_commits?()
click to toggle source
# File lib/git-blame-color/formatter.rb, line 19 def show_boundary_commits? @options.include?(:show_boundary_commits) ? !!@options[:show_boundary_commits] : true end
Private Instance Methods
color_coded_hash(commit)
click to toggle source
# File lib/git-blame-color/formatter.rb, line 52 def color_coded_hash(commit) if show_boundary_commits? Rainbow(hash_to_s(commit)).yellow else ' ' * 8 end end
hash_length()
click to toggle source
# File lib/git-blame-color/formatter.rb, line 40 def hash_length long_hashes? ? 40 : 8 end
hash_to_s(commit)
click to toggle source
# File lib/git-blame-color/formatter.rb, line 44 def hash_to_s(commit) if commit.boundary? "^#{commit.hash[0,hash_length-1]}" else commit.hash[0,hash_length] end end
line_number_to_s(commit)
click to toggle source
# File lib/git-blame-color/formatter.rb, line 64 def line_number_to_s(commit) sprintf('%*s', line_number_width, commit.line_number.to_s) end
timestamp_to_s(commit)
click to toggle source
# File lib/git-blame-color/formatter.rb, line 68 def timestamp_to_s(commit) if raw_timestamps? commit.timestamp else timestamp_to_time(commit).strftime('%Y-%m-%d') end end
timestamp_to_time(commit)
click to toggle source
# File lib/git-blame-color/formatter.rb, line 76 def timestamp_to_time(commit) stamp = commit.timestamp zone = commit.timezone front_zone, back_zone = zone[0..-3], zone[-2,2] zone = "#{front_zone}:#{back_zone}" t = Time.at(stamp.to_i) Time.new(t.year, t.month, t.day, t.hour, t.min, t.sec, zone) end