Module: LedgerSync::Util::StringHelpers
- Defined in:
- lib/ledger_sync/util/string_helpers.rb
Class Method Summary collapse
- .camelcase(str) ⇒ Object
- .inflect(str) ⇒ Object
- .underscore(str) ⇒ Object
- .underscore!(str) ⇒ Object
Class Method Details
.camelcase(str) ⇒ Object
8 9 10 |
# File 'lib/ledger_sync/util/string_helpers.rb', line 8 def camelcase(str) str.to_s.split('/').map { |e| inflect(e.split('_').collect(&:camelcase).join) }.join('::') end |
.inflect(str) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ledger_sync/util/string_helpers.rb', line 24 def inflect(str) return str unless LedgerSync.respond_to?(:ledgers) LedgerSync.ledgers.inflections.each do |inflection| next unless inflection.downcase == str.downcase return inflection end str end |
.underscore(str) ⇒ Object
20 21 22 |
# File 'lib/ledger_sync/util/string_helpers.rb', line 20 def underscore(str) str.dup.tap(&method(:underscore!)) end |
.underscore!(str) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/ledger_sync/util/string_helpers.rb', line 12 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 |