Sha256: 829b1db6b58d0f045b8ada105bb8cf2c63af3aaa2ffa7f06ae5d90b2955a38f1

Contents?: true

Size: 936 Bytes

Versions: 11

Compression:

Stored size: 936 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

      def self.stringify_symbols(array)
        array.map {|e| e.is_a?(Symbol) ? e.to_s : e }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ec2-host-1.0.3 lib/ec2/host/string_util.rb
ec2-host-1.0.2 lib/ec2/host/string_util.rb
ec2-host-1.0.1 lib/ec2/host/string_util.rb
ec2-host-1.0.0 lib/ec2/host/string_util.rb
ec2-host-0.6.0 lib/ec2/host/string_util.rb
ec2-host-0.5.9 lib/ec2/host/string_util.rb
ec2-host-0.5.8 lib/ec2/host/string_util.rb
ec2-host-0.5.7 lib/ec2/host/string_util.rb
ec2-host-0.5.6 lib/ec2/host/string_util.rb
ec2-host-0.5.5 lib/ec2/host/string_util.rb
ec2-host-0.5.4 lib/ec2/host/string_util.rb