Sha256: c2ee39e99f55365a6822d32460ae06cc376a3c0a50ee7f85c9004bcb81010dae

Contents?: true

Size: 793 Bytes

Versions: 8

Compression:

Stored size: 793 Bytes

Contents

module LedgerSync
  module Util
    module StringHelpers
      extend self

      def camelcase(str)
        str.to_s.split('/').map { |e| e.split('_').collect(&:capitalize).map(&method(:inflect)).join }.join('::')
      end

      # def underscore!(str)
      #   str.gsub!(/(.)([A-Z])/, '\1_\2')
      #   str.downcase!
      # end

      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

      def underscore(str)
        str.dup.tap(&method(:underscore!))
      end

      def inflect(str)
        case str.downcase
        when 'quickbooks'
          'QuickBooks'
        else
          str
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ledger_sync-1.1.3 lib/ledger_sync/util/string_helpers.rb
ledger_sync-1.1.2 lib/ledger_sync/util/string_helpers.rb
ledger_sync-1.1.1 lib/ledger_sync/util/string_helpers.rb
ledger_sync-1.0.10 lib/ledger_sync/util/string_helpers.rb
ledger_sync-1.0.9 lib/ledger_sync/util/string_helpers.rb
ledger_sync-1.0.3 lib/ledger_sync/util/string_helpers.rb
ledger_sync-1.0.2 lib/ledger_sync/util/string_helpers.rb
ledger_sync-1.0.0 lib/ledger_sync/util/string_helpers.rb