Sha256: ee94205255c040ddb1edb786b8e4a8f5c377b7f36d13fb5b181ee59b4b965e5c

Contents?: true

Size: 831 Bytes

Versions: 24

Compression:

Stored size: 831 Bytes

Contents

class EC2
  class Host
    # If want sophisticated utility, better to use ActiveSupport
    module StringUtil
      def self.camelize(string)
        string = string.sub(/^[a-z\d]*/) { $&.capitalize }
        string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { $2.capitalize }
        string.gsub!(/\//, '::')
        string
      end

      def self.underscore(camel_cased_word)
        return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
        word = camel_cased_word.to_s.gsub(/::/, '/')
        word.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

      def self.pluralize(string)
        "#{string.chomp('s')}s"
      end

      def self.singularize(string)
        string.chomp('s')
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
ec2-host-0.5.3 lib/ec2/host/string_util.rb
ec2-host-0.5.2 lib/ec2/host/string_util.rb
ec2-host-0.5.1 lib/ec2/host/string_util.rb
ec2-host-0.5.0 lib/ec2/host/string_util.rb
ec2-host-0.4.2 lib/ec2/host/string_util.rb
ec2-host-0.4.1 lib/ec2/host/string_util.rb
ec2-host-0.4.0 lib/ec2/host/string_util.rb
ec2-host-0.3.1 lib/ec2/host/string_util.rb
ec2-host-0.3.0 lib/ec2/host/string_util.rb
ec2-host-0.2.4 lib/ec2/host/string_util.rb
ec2-host-0.2.3 lib/ec2/host/string_util.rb
ec2-host-0.2.1 lib/ec2/host/string_util.rb
ec2-host-0.2.0 lib/ec2/host/string_util.rb
ec2-host-0.1.1 lib/ec2/host/string_util.rb
ec2-host-0.1.0 lib/ec2/host/string_util.rb
ec2-host-0.0.9 lib/ec2/host/string_util.rb
ec2-host-0.0.8 lib/ec2/host/string_util.rb
ec2-host-0.0.7 lib/ec2/host/string_util.rb
ec2-host-0.0.6 lib/ec2/host/string_util.rb
ec2-host-0.0.5 lib/ec2/host/string_util.rb