module RubyBreaker::Util
This module has utility functions that are useful across all components in the project.
Public Class Methods
camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
click to toggle source
File activesupport/lib/active_support/inflector/methods.rb
# File lib/rubybreaker/util.rb, line 46 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(/(?:^|_)(.)/) { $1.upcase } else lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1] end end
ordinalize(number)
click to toggle source
File lib/active_support/inflector.rb, line 295
# File lib/rubybreaker/util.rb, line 21 def self.ordinalize(number) if (11..13).include?(number.to_i % 100) "#{number}th" else case number.to_i % 10 when 1; "#{number}st" when 2; "#{number}nd" when 3; "#{number}rd" else "#{number}th" end end end
underscore(camel_cased_word)
click to toggle source
File activesupport/lib/active_support/inflector/methods.rb, line 48
# File lib/rubybreaker/util.rb, line 35 def self.underscore(camel_cased_word) word = camel_cased_word.to_s.dup word.gsub!(/::/, '/') word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word end
uneigen(mod_str)
click to toggle source
# File lib/rubybreaker/util.rb, line 11 def self.uneigen(mod_str) result = /^#<Class:(.+)>#/.match(mod_str) if result return result[0] else return mod_str end end