Module: Ebay::Inflections
- Defined in:
- lib/ebay/inflections.rb
Constant Summary
- UPCASE_TOKENS =
/(Id$|Cs|Xsl|Url|Rtq|Aaq)/- DOWNCASE_TOKENS =
/^(eBx|EBx)/- NAME_MAPPINGS =
{ 'ebay' => 'eBay', 'paypal' => 'PayPal', 'vero' => 'VeRO' }
Instance Method Summary (collapse)
- - (Object) downcase_first_character(string)
- - (Object) ebay_camelize(lower_case_and_underscored_word)
- - (Object) ebay_underscore(camel_cased_word)
- - (Object) underscore(camel_cased_word)
- - (Object) upcase_first_character(string)
Instance Method Details
- (Object) downcase_first_character(string)
17 18 19 |
# File 'lib/ebay/inflections.rb', line 17 def downcase_first_character(string) string.sub(/^(.)/) { $1.downcase } end |
- (Object) ebay_camelize(lower_case_and_underscored_word)
29 30 31 32 33 34 |
# File 'lib/ebay/inflections.rb', line 29 def ebay_camelize(lower_case_and_underscored_word) lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }. gsub(/(^|_)(.)/) { $2.upcase }. gsub(/(#{NAME_MAPPINGS.keys.collect{|k| k.capitalize}.join('|')})/){ NAME_MAPPINGS[$1.downcase] }. gsub(UPCASE_TOKENS) { $1.upcase } end |
- (Object) ebay_underscore(camel_cased_word)
36 37 38 39 40 41 |
# File 'lib/ebay/inflections.rb', line 36 def ebay_underscore(camel_cased_word) underscore(camel_cased_word.to_s.gsub(/(#{NAME_MAPPINGS.values.join('|')})/i){ upcase_first_character($1.downcase) }. gsub(DOWNCASE_TOKENS){ $1.downcase }. gsub(/(ids$)/i) { $1.upcase } ) end |
- (Object) underscore(camel_cased_word)
21 22 23 24 25 26 27 |
# File 'lib/ebay/inflections.rb', line 21 def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |
- (Object) upcase_first_character(string)
13 14 15 |
# File 'lib/ebay/inflections.rb', line 13 def upcase_first_character(string) string.sub(/^(.)/) { $1.upcase } end |