Module: QboApi::Entity

Included in:
QboApi
Defined in:
lib/qbo_api/entity.rb

Instance Method Summary collapse

Instance Method Details

#extract_entity_from_query(query, to_sym: false) ⇒ Object



79
80
81
82
83
# File 'lib/qbo_api/entity.rb', line 79

def extract_entity_from_query(query, to_sym: false)
  if m = query.match(/from\s+(\w+)\s/i)
    (to_sym ? m[1].downcase.to_sym : m[1].capitalize) if m[1]
  end
end

#is_name_list_entity?(entity) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/qbo_api/entity.rb', line 44

def is_name_list_entity?(entity)
  name_list_entities.include?(singular(entity))
end

#is_transaction_entity?(entity) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/qbo_api/entity.rb', line 20

def is_transaction_entity?(entity)
  transaction_entities.include?(singular(entity))
end

#name_list_entitiesObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/qbo_api/entity.rb', line 48

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



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/qbo_api/entity.rb', line 4

def singular(entity)
  e = snake_to_camel(entity)
  case e
  when 'Classes'
    'Class'
  when /^(Entitlements|Preferences)$/
    e
  else
    e.chomp('s')
  end
end

#snake_to_camel(sym) ⇒ Object



16
17
18
# File 'lib/qbo_api/entity.rb', line 16

def snake_to_camel(sym)
  sym.to_s.split('_').collect(&:capitalize).join
end

#supporting_entitiesObject



69
70
71
72
73
74
75
76
77
# File 'lib/qbo_api/entity.rb', line 69

def supporting_entities
  %w{
    Attachable
    CompanyInfo
    Entitlements
    ExchangeRate
    Preferences
  }
end

#transaction_entitiesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/qbo_api/entity.rb', line 24

def transaction_entities
  %w{
    Bill
    BillPayment
    CreditMemo
    Deposit
    Estimate
    Invoice
    JournalEntry
    Payment
    Purchase
    PurchaseOrder
    RefundReceipt
    SalesReceipt
    TimeActivity
    Transfer
    VendorCredit
  }
end