Module: LedgerSync::Util::StringHelpers
- Extended by:
- StringHelpers
- Included in:
- StringHelpers
- Defined in:
- lib/ledger_sync/util/string_helpers.rb
Instance Method Summary collapse
- #camelcase(str) ⇒ Object
- #inflect(str) ⇒ Object
- #underscore(str) ⇒ Object
-
#underscore!(str) ⇒ Object
def underscore!(str) str.gsub!(/(.)()/, ‘1_2’) str.downcase! end.
Instance Method Details
#camelcase(str) ⇒ Object
6 7 8 |
# File 'lib/ledger_sync/util/string_helpers.rb', line 6 def camelcase(str) str.to_s.split('/').map { |e| e.split('_').collect(&:capitalize).map(&method(:inflect)).join }.join('::') end |
#inflect(str) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/ledger_sync/util/string_helpers.rb', line 27 def inflect(str) case str.downcase when 'quickbooks' 'QuickBooks' else str end end |
#underscore(str) ⇒ Object
23 24 25 |
# File 'lib/ledger_sync/util/string_helpers.rb', line 23 def underscore(str) str.dup.tap(&method(:underscore!)) end |
#underscore!(str) ⇒ Object
def underscore!(str)
str.gsub!(/(.)([A-Z])/, '\1_\2')
str.downcase!
end
15 16 17 18 19 20 21 |
# File 'lib/ledger_sync/util/string_helpers.rb', line 15 def underscore!(str) str.gsub!(/::/, '/') str.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') str.gsub!(/([a-z\d])([A-Z])/, '\1_\2') str.tr!('-', '_') str.downcase! end |