Module: GitTopic::Formatter::Helper

Included in:
Branches, Topics
Defined in:
lib/git_topic/formatter/helper.rb

Overview

Helper class for Formatter classes

Instance Method Summary collapse

Instance Method Details

#truncate(str, truncate_at: 20) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/git_topic/formatter/helper.rb', line 7

def truncate(str, truncate_at: 20)
  omission = '...'
  length_with_room_for_omission = truncate_at - omission.length
  if str.length > truncate_at
    "#{str[0, length_with_room_for_omission]}#{omission}"
  else
    str
  end
end