Module: QboApi::Entity
- Included in:
- QboApi
- Defined in:
- lib/qbo_api/entity.rb
Instance Method Summary collapse
- #entity_path(entity) ⇒ Object
- #extract_entity_from_query(query, to_sym: false) ⇒ Object
- #is_name_list_entity?(entity) ⇒ Boolean
- #is_transaction_entity?(entity) ⇒ Boolean
- #is_voidable_transaction_entity?(entity) ⇒ Boolean
- #name_list_entities ⇒ Object
- #singular(entity) ⇒ Object
- #snake_to_camel(sym) ⇒ Object
- #supporting_entities ⇒ Object
- #transaction_entities ⇒ Object
- #voidable_transaction_entities ⇒ Object
Instance Method Details
#entity_path(entity) ⇒ Object
15 16 17 |
# File 'lib/qbo_api/entity.rb', line 15 def entity_path(entity) "#{realm_id}/#{singular(entity).downcase}" end |
#extract_entity_from_query(query, to_sym: false) ⇒ Object
96 97 98 99 100 |
# File 'lib/qbo_api/entity.rb', line 96 def extract_entity_from_query(query, to_sym: false) if m = query.match(/from\s+(\w+)(?:$|\s)/i) (to_sym ? underscore(m[1]).to_sym : m[1]) if m[1] end end |
#is_name_list_entity?(entity) ⇒ Boolean
60 61 62 |
# File 'lib/qbo_api/entity.rb', line 60 def is_name_list_entity?(entity) name_list_entities.include?(singular(entity)) end |
#is_transaction_entity?(entity) ⇒ Boolean
36 37 38 |
# File 'lib/qbo_api/entity.rb', line 36 def is_transaction_entity?(entity) transaction_entities.include?(singular(entity)) end |
#is_voidable_transaction_entity?(entity) ⇒ Boolean
23 24 25 |
# File 'lib/qbo_api/entity.rb', line 23 def is_voidable_transaction_entity?(entity) voidable_transaction_entities.include?(singular(entity)) end |
#name_list_entities ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/qbo_api/entity.rb', line 64 def name_list_entities %w{ Account Budget Class CompanyCurrency Customer Department Employee Item JournalCode PaymentMethod TaxAgency TaxCode TaxRate TaxService Term Vendor } end |
#singular(entity) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/qbo_api/entity.rb', line 3 def singular(entity) e = snake_to_camel(entity) case e when 'Classes', 'Class' 'Class' when 'Entitlements', 'Preferences' e else e.chomp('s') end end |
#snake_to_camel(sym) ⇒ Object
19 20 21 |
# File 'lib/qbo_api/entity.rb', line 19 def snake_to_camel(sym) sym.to_s.split('_').collect(&:capitalize).join end |
#supporting_entities ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/qbo_api/entity.rb', line 85 def supporting_entities %w{ Attachable Batch CompanyInfo Entitlements ExchangeRate Preferences } end |
#transaction_entities ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/qbo_api/entity.rb', line 40 def transaction_entities %w{ Bill BillPayment CreditMemo Deposit Estimate Invoice JournalEntry Payment Purchase PurchaseOrder RefundReceipt SalesReceipt TimeActivity Transfer VendorCredit } end |
#voidable_transaction_entities ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/qbo_api/entity.rb', line 27 def voidable_transaction_entities %w{ BillPayment Invoice Payment SalesReceipt } end |