Module: RubyBreaker::Util

Defined in:
lib/rubybreaker/util.rb

Overview

This module has utility functions that are useful across all components in the project.

Class Method Summary collapse

Class Method Details

.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object

File activesupport/lib/active_support/inflector/methods.rb



46
47
48
49
50
51
52
# 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) ⇒ Object

File lib/active_support/inflector.rb, line 295



21
22
23
24
25
26
27
28
29
30
31
32
# 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) ⇒ Object

File activesupport/lib/active_support/inflector/methods.rb, line 48



35
36
37
38
39
40
41
42
43
# 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) ⇒ Object



11
12
13
14
15
16
17
18
# 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