Sha256: 4a07d28e7517473519011ca44afaf6761d705d679365b29e8c5975482da8f893

Contents?: true

Size: 544 Bytes

Versions: 53

Compression:

Stored size: 544 Bytes

Contents

module Postmark
  module Inflector

    extend self

    def to_postmark(name)
      name.to_s.split('_').map { |part| capitalize_first_letter(part) }.join('')
    end

    def to_ruby(name)
      name.to_s.scan(camel_case_regexp).join('_').downcase.to_sym
    end

    def camel_case_regexp
      /(?:[A-Z](?:(?:[A-Z]+(?![a-z\d]))|[a-z\d]*))|[a-z\d\_]+/
    end

    protected

    def capitalize_first_letter(str)
      if str.length > 0
        str.slice(0..0).capitalize + str.slice(1..-1)
      else
        str
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
postmark-1.25.1 lib/postmark/inflector.rb
postmark-1.25.0 lib/postmark/inflector.rb
postmark-1.24.1 lib/postmark/inflector.rb
postmark-1.24.0 lib/postmark/inflector.rb
postmark-1.23.0 lib/postmark/inflector.rb
postmark-1.22.3 lib/postmark/inflector.rb
postmark-1.22.2 lib/postmark/inflector.rb
postmark-1.22.1 lib/postmark/inflector.rb
postmark-1.22.0 lib/postmark/inflector.rb
postmark-1.21.8 lib/postmark/inflector.rb
postmark-1.21.7 lib/postmark/inflector.rb
postmark-1.21.6 lib/postmark/inflector.rb
postmark-1.21.5 lib/postmark/inflector.rb
postmark-1.21.4 lib/postmark/inflector.rb
postmark-1.21.3 lib/postmark/inflector.rb
postmark-1.21.2 lib/postmark/inflector.rb
postmark-1.21.1 lib/postmark/inflector.rb
postmark-1.21.0 lib/postmark/inflector.rb
postmark-1.20.0 lib/postmark/inflector.rb
postmark-1.19.2 lib/postmark/inflector.rb