module Cucumber::Messages::Message::Utils::ClassMethods

Public Instance Methods

camelize(term) click to toggle source

Converts strings to UpperCamelCase.

camelize('gherkin_document')                # => "GherkinDocument"

This is a simplified version of the Ruby on Rails implementation github.com/rails/rails/blob/v6.1.3.2/activesupport/lib/active_support/inflector/methods.rb#L69

# File lib/cucumber/messages/message/utils.rb, line 37
def camelize(term)
  camelized = term.to_s
  camelized.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
  camelized
end
underscore(term) click to toggle source

Makes an underscored, lowercase form from the expression in the string.

underscore('GherkinDocument')         # => "gherkin_document"

This is a simplified version of the Ruby on Rails implementation github.com/rails/rails/blob/v6.1.3.2/activesupport/lib/active_support/inflector/methods.rb#L92

# File lib/cucumber/messages/message/utils.rb, line 19
def underscore(term)
  return term unless /[A-Z-]/.match?(term)

  word = term.gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end