Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#danger_pluralize(count) ⇒ String

Returns the plural form of self determined by count.

Returns:

  • (String)

    the plural form of self determined by count



3
4
5
# File 'lib/danger/core_ext/string.rb', line 3

def danger_pluralize(count)
  "#{count} #{self}#{'s' unless count == 1}"
end

#danger_truncate(limit) ⇒ String

Returns truncates string with ellipsis when exceeding the limit.

Returns:

  • (String)

    truncates string with ellipsis when exceeding the limit



17
18
19
# File 'lib/danger/core_ext/string.rb', line 17

def danger_truncate(limit)
  length > limit ? "#{self[0...limit]}..." : self
end

#danger_underscoreString

Returns converts to underscored, lowercase form.

Returns:

  • (String)

    converts to underscored, lowercase form



8
9
10
11
12
13
14
# File 'lib/danger/core_ext/string.rb', line 8

def danger_underscore
  self.gsub(/::/, "/".freeze).
    gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'.freeze).
    gsub(/([a-z\d])([A-Z])/, '\1_\2'.freeze).
    tr("-".freeze, "_".freeze).
    downcase
end