Method: ChefAPI::Util#truncate

Defined in:
lib/chef-api/util.rb

#truncate(string, options = {}) ⇒ Object

Truncate the given string to a certain number of characters.

Parameters:

  • string (String)

    the string to truncate

  • options (Hash) (defaults to: {})

    the list of options (such as length)



48
49
50
51
52
53
54
55
56
# File 'lib/chef-api/util.rb', line 48

def truncate(string, options = {})
  length = options[:length] || 30

  if string.length > length
    string[0..length - 3] + "..."
  else
    string
  end
end