Module: Myxy::Utils
- Defined in:
- lib/myxy/utils.rb
Class Method Summary collapse
- .camelize(word, uppercase_first_letter = true) ⇒ Object
- .collection_path(class_name) ⇒ Object
- .demodulize(class_name_in_module) ⇒ Object
- .modulize(class_name) ⇒ Object
- .normalize_attributes(attributes) ⇒ Object
- .pluralize(word) ⇒ Object
Class Method Details
.camelize(word, uppercase_first_letter = true) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/myxy/utils.rb', line 19 def self.camelize(word, uppercase_first_letter = true) if uppercase_first_letter word.to_s.gsub(%r{/\/(.?)/}) { '::' + $1.upcase } .gsub(/(^|_)(.)/) { $2.upcase } else word[0] + Utils.camelize(word)[1..-1] end end |
.collection_path(class_name) ⇒ Object
15 16 17 |
# File 'lib/myxy/utils.rb', line 15 def self.collection_path(class_name) (Utils.pluralize Utils.demodulize class_name).downcase end |
.demodulize(class_name_in_module) ⇒ Object
3 4 5 |
# File 'lib/myxy/utils.rb', line 3 def self.demodulize(class_name_in_module) class_name_in_module.to_s.sub(/^.*::/, '') end |
.modulize(class_name) ⇒ Object
11 12 13 |
# File 'lib/myxy/utils.rb', line 11 def self.modulize(class_name) "Myxy::#{class_name}" end |
.normalize_attributes(attributes) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/myxy/utils.rb', line 28 def self.normalize_attributes(attributes) attributes.inject({}) do |attribute, (k, v)| attribute[k.to_sym] = v attribute end end |
.pluralize(word) ⇒ Object
7 8 9 |
# File 'lib/myxy/utils.rb', line 7 def self.pluralize(word) word.to_s.sub(/([^s])$/, '\1s') end |