Sha256: aea614175d7316e072686b335c109f7e3505bff37f98d1b5fee7bf9299d1e82d

Contents?: true

Size: 1.41 KB

Versions: 22

Compression:

Stored size: 1.41 KB

Contents

module Cucumber
  module Messages
    class Message
      module Utils
        def self.included(other)
          other.extend(ClassMethods)
        end

        module ClassMethods

          ##
          # 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
          # https://github.com/rails/rails/blob/v6.1.3.2/activesupport/lib/active_support/inflector/methods.rb#L92

          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

          ##
          # Converts strings to UpperCamelCase.
          #
          #   camelize('gherkin_document')                # => "GherkinDocument"
          #
          # This is a simplified version of the Ruby on Rails implementation
          # https://github.com/rails/rails/blob/v6.1.3.2/activesupport/lib/active_support/inflector/methods.rb#L69

          def camelize(term)
            camelized = term.to_s
            camelized.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
            camelized
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-messages-22.0.0/lib/cucumber/messages/message/utils.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-messages-21.0.1/lib/cucumber/messages/message/utils.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/message/utils.rb
cucumber-messages-22.0.0 lib/cucumber/messages/message/utils.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/message/utils.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/message/utils.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-messages-18.0.0/lib/cucumber/messages/message/utils.rb
cucumber-messages-21.0.1 lib/cucumber/messages/message/utils.rb
cucumber-messages-21.0.0 lib/cucumber/messages/message/utils.rb
cucumber-messages-20.0.0 lib/cucumber/messages/message/utils.rb
cucumber-messages-19.1.4 lib/cucumber/messages/message/utils.rb
cucumber-messages-19.1.3 lib/cucumber/messages/message/utils.rb
cucumber-messages-19.1.2 lib/cucumber/messages/message/utils.rb
cucumber-messages-19.1.1 lib/cucumber/messages/message/utils.rb
cucumber-messages-19.1.0 lib/cucumber/messages/message/utils.rb
cucumber-messages-19.0.0 lib/cucumber/messages/message/utils.rb
cucumber-messages-18.0.0 lib/cucumber/messages/message/utils.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-messages-17.1.1/lib/cucumber/messages/message/utils.rb
cucumber-messages-17.1.1 lib/cucumber/messages/message/utils.rb
cucumber-messages-17.1.0 lib/cucumber/messages/message/utils.rb