Class: Quickbooks::Options

Inherits:
Object show all
Defined in:
lib/quickbooks/option.rb

Overview

A collection of Option objects. Can validate that a given object contains all required options and allowed values in this collection.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_xsd(xsd) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/quickbooks/option.rb', line 4

def self.from_xsd(xsd)
  options = new
  # puts "Options from xsd: #{xsd.inspect}"
  xsd.type.items.select {|i| i.class == Quickbooks::XSD::Attribute}.each do |option_xsd|
    options << Option.from_xsd(option_xsd)
  end
  options
end

Instance Method Details

#<<(option) ⇒ Object



13
14
15
# File 'lib/quickbooks/option.rb', line 13

def <<(option)
  options << option
end

#[](name) ⇒ Object



30
31
32
33
# File 'lib/quickbooks/option.rb', line 30

def [](name)
  name = name.to_s
  options.select {|option| option.name == name}[0]
end

#defaultsObject



26
27
28
# File 'lib/quickbooks/option.rb', line 26

def defaults
  options.inject({}) {|h,option| h[option.name.to_s] = option.default if option.default && option.required?; h}
end

#delete(name) ⇒ Object



35
36
37
# File 'lib/quickbooks/option.rb', line 35

def delete(name)
  options.reject! {|a| a.name == name}
end

#include?(name) ⇒ Boolean

Returns:



22
23
24
# File 'lib/quickbooks/option.rb', line 22

def include?(name)
  options.any? {|option| option.name == name}
end

#validate(object) ⇒ Object



17
18
19
20
# File 'lib/quickbooks/option.rb', line 17

def validate(object)
  puts "Validating #{object.inspect}!" if $DEBUG
  options.check_all? { |option| option.validate(object) }
end