Class: QBFC::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/qbfc/base.rb

Overview

Base is the…um…“base” class from which Element, Info, and Report inherit. It defines methods that the three share.

Direct Known Subclasses

Element, Info, Report

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sess, ole = nil) ⇒ Base

Create an instance of this Element or Report.

  • sess: An open QBFC::Session object that will recieve all requests

  • ole: An optional QBFC::OLEWrapper object representing a response to a QueryRq. It is unlikely that this will be used directly.



55
56
57
58
# File 'lib/qbfc/base.rb', line 55

def initialize(sess, ole = nil)
  @sess, @ole = sess, ole    
  @ole = QBFC::OLEWrapper.new(@ole) if @ole.kind_of?(WIN32OLE)    
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *params) ⇒ Object

Pass missing methods to OLEWrapper#qbfc_method_missing to handle checking if there is a related OLE method to run.



72
73
74
# File 'lib/qbfc/base.rb', line 72

def method_missing(symbol, *params)
  @ole.qbfc_method_missing(@sess, symbol, *params)
end

Class Method Details

.create_query(sess) ⇒ Object

A convenience method for creating and returning a Query Request for this class.



36
37
38
# File 'lib/qbfc/base.rb', line 36

def create_query(sess)
  QBFC::Request.new(sess, "#{qb_name}Query")
end

.is_base_class?Boolean

is_base_class? is used by Element and subclasses. It is included in Base because some Base methods may check for it.

Returns:

  • (Boolean)


9
10
11
# File 'lib/qbfc/base.rb', line 9

def is_base_class? #:nodoc:
  false
end

.parse_find_args(*args) ⇒ Object

Element::find and Info::get receive optional arguments which can include a Request object and/or an options Hash. parse_find_args gets these arguments into a set that is easier to deal with.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/qbfc/base.rb', line 16

def parse_find_args(*args)
  request = args[0].kind_of?(QBFC::Request) ? args[0].dup : nil
  options = args[-1].kind_of?(Hash) ? args[-1].dup : {}
  
  # base classes will need to pass a subset of options to
  # the ChildClass.find . Also, the actually options to the
  # BaseClass.find Request cannot include owner_id.
  if is_base_class?
    base_options = options.dup 
    base_options.delete(:conditions)
    options.delete(:owner_id)
  else
    base_options = nil
  end
  
  return request, options, base_options
end

.qb_nameObject

The QuickBooks name for this Element or Report. It typically matches the last part of class name. Used in determining names of Requests and other OLE methods.



46
47
48
# File 'lib/qbfc/base.rb', line 46

def qb_name
  self.name.split('::').last
end

Instance Method Details

#ole_methodsObject

List the methods of the OLE object



61
62
63
# File 'lib/qbfc/base.rb', line 61

def ole_methods
  @ole.ole_methods
end

#qb_nameObject

Name of the QuickBooks Element or Query represented by this class.



77
78
79
# File 'lib/qbfc/base.rb', line 77

def qb_name
  self.class.qb_name
end

#respond_to_ole?(symbol) ⇒ Boolean

Check if the OLE object responds to a given method

Returns:

  • (Boolean)


66
67
68
# File 'lib/qbfc/base.rb', line 66

def respond_to_ole?(symbol)
  @ole.respond_to_ole?(symbol)
end