Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/utils/utils.rb
Instance Method Summary collapse
- #capitalize_first ⇒ Object
- #capitalize_first! ⇒ Object
- #delete_last_path_component ⇒ Object
- #include_one_of?(*array) ⇒ Boolean
- #lowercase_first ⇒ Object
- #path_intersection(other) ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#capitalize_first ⇒ Object
18 19 20 |
# File 'lib/utils/utils.rb', line 18 def capitalize_first self.slice(0,1).capitalize + self.slice(1..-1) end |
#capitalize_first! ⇒ Object
21 22 23 |
# File 'lib/utils/utils.rb', line 21 def capitalize_first! self.replace(self.capitalize_first) end |
#delete_last_path_component ⇒ Object
54 55 56 |
# File 'lib/utils/utils.rb', line 54 def delete_last_path_component self.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR) end |
#include_one_of?(*array) ⇒ Boolean
12 13 14 15 16 17 |
# File 'lib/utils/utils.rb', line 12 def include_one_of?(*array) array.flatten.each do |str| return true if self.include?(str) end false end |
#lowercase_first ⇒ Object
24 25 26 27 |
# File 'lib/utils/utils.rb', line 24 def lowercase_first str = to_s str[0,1].downcase + str[1..-1] end |
#path_intersection(other) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/utils/utils.rb', line 35 def path_intersection(other) component_start = 0 (0..[other.size, self.size].min).each { |i| if self[i] == '/' component_start = i end if self[i] != other[i] if i > 0 return self[0..component_start] else return '' end end } self end |
#underscore ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/utils/utils.rb', line 28 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |