Module: Cucumber::Messages::Message::Utils::ClassMethods

Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/message/utils.rb

Instance Method Summary collapse

Instance Method Details

#camelize(term) ⇒ Object

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



37
38
39
40
41
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/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) ⇒ Object

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



19
20
21
22
23
24
25
26
27
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/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