Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/lazyman/ext/string.rb
Instance Method Summary collapse
Instance Method Details
#acronym_regex ⇒ Object
23 24 25 |
# File 'lib/lazyman/ext/string.rb', line 23 def acronym_regex /(?=a)b/ end |
#lazy_to_hash ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/lazyman/ext/string.rb', line 2 def lazy_to_hash hash = { } return hash if self.empty? arr = self.split(',').map { |i| i.strip } arr.each do |key| hash[key.to_sym] = true end #each hash end |
#underscore ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lazyman/ext/string.rb', line 12 def underscore return self unless self =~ /[A-Z-]|::/ word = self.to_s.gsub(/::/, '/') word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" } word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end |