axsh/isono · util.rb
ruby logo
def snake_case(str)
      return str.downcase if str.match(/\A[A-Z]+\z/)
      str.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
        gsub(/([a-z])([A-Z])/, '\1_\2').
        downcase
    end
Similar code snippets
1.
andymeneely/squib · data_frame.rb
Match rating: 73.64% · See similar code snippets
ruby logo
def snake_case(str)
      str.to_s.
          strip.
          gsub(/\s+/,'_').
          gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
          gsub(/([a-z]+)([A-Z])/,'\1_\2').
          downcase.
          to_sym
    end
2.
david942j/memory_io · util.rb
Match rating: 63.52% · See similar code snippets
ruby logo
def underscore(str)
      return '' if str.empty?

      str = str.gsub('::', '/')
      str.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
      str.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
      str.downcase!
      str
    end
3.
shioyama/mobility · util.rb
Match rating: 62.21% · See similar code snippets
ruby logo
def underscore(str)
      call_or_yield str do
        str.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
          gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
      end
    end
4.
soulcutter/saxerator · builder.rb
Match rating: 53.53% · See similar code snippets
ruby logo
def camel_case(str)
      str = str.to_s
      return str if str !~ /_/ && str =~ /[A-Z]+.*/
      str.split('_').map(&:capitalize).join
    end
5.
fixrb/matchi · matchers_base.rb
Match rating: 52.16% · See similar code snippets
ruby logo
def to_s
      s = matcher_name
          .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
          .gsub(/([a-z\d])([A-Z])/, '\1_\2')
          .downcase

      defined?(@expected) ? [s, @expected.inspect].join(' ') : s
    end
6.
salesforce/flo · config.rb
Match rating: 52.01% · See similar code snippets
ruby logo
def camel_case(str)
      return str if str !~ /_/ && str =~ /[A-Z]+.*/
      str.split('_').map{|e| e.capitalize}.join
    end
7.
Match rating: 51.24% · See similar code snippets
ruby logo
def to_camel_case(str)
      str = "_#{str}"
      str.gsub!(%r{_[a-z]}) { |snake| snake.slice(1).upcase }
      str.gsub!('/', '::')
      str
    end
8.
leapcode/amber · table_of_contents.rb
Match rating: 48.84% · See similar code snippets
ruby logo
def nameize(str)
      str = str.dup
      str.gsub!(/&(\w{2,6}?|#[0-9A-Fa-f]{2,6});/,'') # remove html entitities
      str.gsub!(/[^- [[:word:]]]/u, '') # remove non-word characters (using unicode definition of a word char)
      str.strip!
      str.downcase!          # upper case characters in urls are confusing
      str.gsub!(/\ +/u, '-') # spaces to dashes, preferred separator char everywhere
      CGI.escape(str)
    end
9.
GlobalNamesArchitecture/dwca_hunter · resource.rb
Match rating: 48.6% · See similar code snippets
ruby logo
def cleanup(str)
      str.strip!
      str.to_i.to_s == str ? str.to_i : str
    end
10.
veny/orientdb4r · utils.rb
Match rating: 48.5% · See similar code snippets
ruby logo
def blank?(str)
      str.nil? or (str.is_a? String and str.strip.empty?)
    end