Module: Ebay::Inflections
- Included in:
- Api, Schema::ApiSchemaImporter, Schema::ClassDefinition, Schema::Enumeration, Schema::Node, Schema::RubyClassGenerator
- Defined in:
- lib/ebay/inflections.rb
Constant Summary collapse
- UPCASE_TOKENS =
/(Id$|Cs|Xsl|Url|Rtq|Aaq)/
- DOWNCASE_TOKENS =
/^(eBx|EBx)/
- NAME_MAPPINGS =
{ 'ebay' => 'eBay', 'paypal' => 'PayPal', 'vero' => 'VeRO' }
Instance Method Summary collapse
- #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) ⇒ Object
Instance Method Details
#downcase_first_character(string) ⇒ Object
16 17 18 |
# File 'lib/ebay/inflections.rb', line 16 def downcase_first_character(string) string.sub(/^(.)/) { $1.downcase } end |
#ebay_camelize(lower_case_and_underscored_word) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/ebay/inflections.rb', line 28 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 |
#ebay_underscore(camel_cased_word) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/ebay/inflections.rb', line 35 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 |
#underscore(camel_cased_word) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/ebay/inflections.rb', line 20 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 |
#upcase_first_character(string) ⇒ Object
12 13 14 |
# File 'lib/ebay/inflections.rb', line 12 def upcase_first_character(string) string.sub(/^(.)/) { $1.upcase } end |