Module: TensorStream::StringHelper
- Included in:
- GraphBuilder, Pbtext, Session
- Defined in:
- lib/tensor_stream/helpers/string_helper.rb
Overview
helper string methods usually found in ActiveSupport but need to replicate here
Instance Method Summary collapse
- #camelize(string, uppercase_first_letter = true) ⇒ Object
- #symbolize_keys(hash) ⇒ Object
- #underscore(string) ⇒ Object
Instance Method Details
#camelize(string, uppercase_first_letter = true) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/tensor_stream/helpers/string_helper.rb', line 5 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 |
#symbolize_keys(hash) ⇒ Object
22 23 24 25 26 |
# File 'lib/tensor_stream/helpers/string_helper.rb', line 22 def symbolize_keys(hash) hash.map do |k, v| [k.to_sym, v] end.to_h end |
#underscore(string) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/tensor_stream/helpers/string_helper.rb', line 14 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 |