Sha256: 44d4fc70fa3874449eccedc230475650596633c5b6be6500b1098503237e5903

Contents?: true

Size: 677 Bytes

Versions: 26

Compression:

Stored size: 677 Bytes

Contents

module Doing
  module Completion
    module StringUtils

      ##
      ## Get short description for command completion
      ##
      ## @return     [String] Short description
      ##
      def short_desc
        split(/[,.]/)[0].sub(/ \(.*?\)?$/, '').strip
      end

      ##
      ## Truncate string from left
      ##
      ## @param      max   The maximum number of characters
      ##
      def ltrunc(max)
        if length > max
          sub(/^.*?(.{#{max - 3}})$/, '...\1')
        else
          self
        end
      end

      def ltrunc!(max)
        replace ltrunc(max)
      end
    end
  end
end

class ::String
  include Doing::Completion::StringUtils
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
doing-2.1.88 lib/doing/completion/completion_string.rb
doing-2.1.87 lib/doing/completion/completion_string.rb
doing-2.1.86 lib/doing/completion/completion_string.rb
doing-2.1.85 lib/doing/completion/completion_string.rb
doing-2.1.84 lib/doing/completion/completion_string.rb
doing-2.1.83 lib/doing/completion/completion_string.rb
doing-2.1.82 lib/doing/completion/completion_string.rb
doing-2.1.81 lib/doing/completion/completion_string.rb
doing-2.1.80 lib/doing/completion/completion_string.rb
doing-2.1.79 lib/doing/completion/completion_string.rb
doing-2.1.78 lib/doing/completion/completion_string.rb
doing-2.1.77 lib/doing/completion/completion_string.rb
doing-2.1.76 lib/doing/completion/completion_string.rb
doing-2.1.75 lib/doing/completion/completion_string.rb
doing-2.1.74 lib/doing/completion/completion_string.rb
doing-2.1.73 lib/doing/completion/completion_string.rb
doing-2.1.72 lib/doing/completion/completion_string.rb
doing-2.1.69 lib/doing/completion/completion_string.rb
doing-2.1.68 lib/doing/completion/completion_string.rb
doing-2.1.66 lib/doing/completion/completion_string.rb