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



5
6
7
# File 'lib/danger/core_ext/string.rb', line 5

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



19
20
21
# File 'lib/danger/core_ext/string.rb', line 19

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



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

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