Sha256: 5eb97cdeee6bf1754dd46d61d88333a199ac62cfac5a4ac5d6f7261cd7f1ea1d

Contents?: true

Size: 795 Bytes

Versions: 11

Compression:

Stored size: 795 Bytes

Contents

module TensorStream
  # helper string methods usually found in ActiveSupport but
  # need to replicate here
  module StringHelper
    def camelize(string, uppercase_first_letter = true)
      string = if uppercase_first_letter
                 string.sub(/^[a-z\d]*/) { $&.capitalize }
               else
                 string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
               end
      string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
    end

    def underscore(string)
      string.gsub(/::/, '/')
            .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
            .gsub(/([a-z\d])([A-Z])/, '\1_\2')
            .tr("-", "_").downcase
    end

    def symbolize_keys(hash)
      hash.map do |k, v|
        [k.to_sym, v]
      end.to_h
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tensor_stream-0.9.8 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.9.7 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.9.6 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.9.5 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.9.2 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.9.1 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.9.0 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.8.6 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.8.5 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.8.1 lib/tensor_stream/helpers/string_helper.rb
tensor_stream-0.8.0 lib/tensor_stream/helpers/string_helper.rb