Class: XeroKiwi::Accounting::ContactGroup
- Inherits:
-
Object
- Object
- XeroKiwi::Accounting::ContactGroup
- Defined in:
- lib/xero_kiwi/accounting/contact_group.rb
Overview
Represents a Xero Contact Group returned by the Accounting API.
See: developer.xero.com/documentation/api/accounting/contactgroups
Constant Summary collapse
- ATTRIBUTES =
{ contact_group_id: "ContactGroupID", name: "Name", status: "Status", contacts: "Contacts" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #active? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attrs, reference: false) ⇒ ContactGroup
constructor
A new instance of ContactGroup.
- #inspect ⇒ Object
- #reference? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attrs, reference: false) ⇒ ContactGroup
Returns a new instance of ContactGroup.
27 28 29 30 31 32 33 34 |
# File 'lib/xero_kiwi/accounting/contact_group.rb', line 27 def initialize(attrs, reference: false) attrs = attrs.transform_keys(&:to_s) @is_reference = reference @contact_group_id = attrs["ContactGroupID"] @name = attrs["Name"] @status = attrs["Status"] @contacts = (attrs["Contacts"] || []).map { |c| Contact.new(c, reference: true) } end |
Class Method Details
.from_response(payload) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/xero_kiwi/accounting/contact_group.rb', line 18 def self.from_response(payload) return [] if payload.nil? items = payload["ContactGroups"] return [] if items.nil? items.map { |attrs| new(attrs) } end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
44 45 46 |
# File 'lib/xero_kiwi/accounting/contact_group.rb', line 44 def ==(other) other.is_a?(ContactGroup) && other.contact_group_id == contact_group_id end |
#active? ⇒ Boolean
38 |
# File 'lib/xero_kiwi/accounting/contact_group.rb', line 38 def active? = status == "ACTIVE" |
#hash ⇒ Object
49 |
# File 'lib/xero_kiwi/accounting/contact_group.rb', line 49 def hash = [self.class, contact_group_id].hash |
#inspect ⇒ Object
51 52 53 54 |
# File 'lib/xero_kiwi/accounting/contact_group.rb', line 51 def inspect "#<#{self.class} contact_group_id=#{contact_group_id.inspect} " \ "name=#{name.inspect} status=#{status.inspect}>" end |
#reference? ⇒ Boolean
36 |
# File 'lib/xero_kiwi/accounting/contact_group.rb', line 36 def reference? = @is_reference |
#to_h ⇒ Object
40 41 42 |
# File 'lib/xero_kiwi/accounting/contact_group.rb', line 40 def to_h ATTRIBUTES.keys.to_h { |key| [key, public_send(key)] } end |