Module: KillBillClient::Utils
Constant Summary collapse
- ACRONYMS =
%w(CBA).freeze
Instance Method Summary collapse
- #acronym?(word) ⇒ Boolean
- #camelize(underscored_word, first_letter = :upper) ⇒ Object
- #demodulize(class_name_in_module) ⇒ Object
- #underscore(camel_cased_word) ⇒ Object
Instance Method Details
#acronym?(word) ⇒ Boolean
31 32 33 |
# File 'lib/killbill_client/utils.rb', line 31 def acronym?(word) ACRONYMS.include?(word.to_s.upcase) end |
#camelize(underscored_word, first_letter = :upper) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/killbill_client/utils.rb', line 5 def camelize(underscored_word, first_letter = :upper) camelized = underscored_word.to_s.split('_').map do |word| if acronym?(word) word.upcase else word[0, 1].upcase + word[1..-1] end end.join camelized = camelized[0, 1].downcase + camelized[1..-1] if first_letter == :lower camelized end |
#demodulize(class_name_in_module) ⇒ Object
17 18 19 |
# File 'lib/killbill_client/utils.rb', line 17 def demodulize(class_name_in_module) class_name_in_module.to_s.sub(/^.*::/, '') end |
#underscore(camel_cased_word) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/killbill_client/utils.rb', line 21 def 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 |