Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/danger/core_ext/string.rb
Instance Method Summary collapse
-
#danger_pluralize(count) ⇒ String
The plural form of self determined by count.
-
#danger_truncate(limit) ⇒ String
Truncates string with ellipsis when exceeding the limit.
-
#danger_underscore ⇒ String
Converts to underscored, lowercase form.
Instance Method Details
#danger_pluralize(count) ⇒ String
Returns 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.
17 18 19 |
# File 'lib/danger/core_ext/string.rb', line 17 def danger_truncate(limit) length > limit ? "#{self[0...limit]}..." : self end |
#danger_underscore ⇒ String
Returns 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 |