Sha256: a6e5a41d3759e8ab642b90c3bd2dfd52063a042e5522bd19ecf14394bfb425fc
Contents?: true
Size: 1.15 KB
Versions: 4
Compression:
Stored size: 1.15 KB
Contents
# Waxx Copyright (c) 2016 ePark labs Inc. & Daniel J. Fitzpatrick <dan@eparklabs.com> All rights reserved. # Released under the Apache Version 2 License. See LICENSE.txt. module Waxx::Util extend self def camel_case(str) title_case(str.to_s.gsub(/[\._-]/,' ')).gsub(' ','') end alias camelize camel_case def label(str) title_case(humanize(str.to_s)) end def humanize(str) underscore(str.to_s).gsub('_',' ').capitalize end def title_case(str) str.to_s.split(' ').map{|t| t.capitalize}.join(' ') end alias titleize title_case def underscore(str) str.to_s.gsub(/::/, '_') .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') .gsub(/([a-z\d])([A-Z])/,'\1_\2') .tr("-", "_").tr(" ","_") .downcase end def app_from_class(cls) cls.to_s.split("::")[1] end def table_from_class(cls) underscore(app_from_class(cls)) end def class_from_table(tbl) tbl.to_s.split("_").map{|i| i.capitalize}.join end def get_const(base_class, *names) names.inject(base_class){|c, n| c.const_get(n.to_s.split("_").map{|i| i.capitalize}.join) } end def qs(str) Waxx::Http.qs(str) end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
waxx-0.2.0 | lib/waxx/util.rb |
waxx-0.1.4 | lib/waxx/util.rb |
waxx-0.1.3 | lib/waxx/util.rb |
waxx-0.1.2 | lib/waxx/util.rb |