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.
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.
19 20 21 |
# File 'lib/danger/core_ext/string.rb', line 19 def danger_truncate(limit) length > limit ? "#{self[0...limit]}..." : self end |
#danger_underscore ⇒ String
Returns 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 |