Sha256: 234184a19f6055125ab956ff61698072cd7463c55ab37bcf103129d3fce19b17

Contents?: true

Size: 1.23 KB

Versions: 61

Compression:

Stored size: 1.23 KB

Contents

module Spider

    module Inflector

        #--
        # From ActiveSupport
        def self.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
            if first_letter_in_uppercase
                lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
            else
                lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
            end
        end

        #--
        # From ActiveSupport
        def self.underscore(camel_cased_word)
            camel_cased_word.to_s.gsub(/::/, '/').
            gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
            gsub(/([a-z\d])([A-Z])/,'\1_\2').
            tr("-", "_").
            downcase
        end
        
        def self.underscore_to_upcasefirst(str)
            upcasefirst(str.gsub(/_+/, ' '))
        end
        
        def self.upcasefirst(str)
            # FIXME: move to language specific!
            no_upcase = ['di', 'da', 'a']
            res = str.split(' ').map do | p | 
                l = p.downcase
                l.gsub(/^[a-z]/){ |a| a.upcase } unless no_upcase.include?(l)
            end
            res.join(' ')
        end
        

    end

end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
spiderfw-1.0.1 lib/spiderfw/utils/inflector.rb
spiderfw-1.0.0 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.39 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.38 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.37 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.35 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.34 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.33 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.32 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.31 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.30 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.29 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.28 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.27 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.26 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.26.pre1 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.25 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.24 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.23 lib/spiderfw/utils/inflector.rb
spiderfw-0.6.22 lib/spiderfw/utils/inflector.rb