Class: AutotaskApi::EntityCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/autotask_api/entity_collection.rb

Constant Summary collapse

PAGE_SIZE =
500

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name, entities, condition, client = AutotaskApi.client) ⇒ EntityCollection

Returns a new instance of EntityCollection.



11
12
13
14
15
16
# File 'lib/autotask_api/entity_collection.rb', line 11

def initialize(class_name, entities, condition, client = AutotaskApi.client)
  @class_name = class_name
  @entities = entities
  @condition = condition
  @client = client
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



9
10
11
# File 'lib/autotask_api/entity_collection.rb', line 9

def class_name
  @class_name
end

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/autotask_api/entity_collection.rb', line 9

def client
  @client
end

#conditionObject

Returns the value of attribute condition.



7
8
9
# File 'lib/autotask_api/entity_collection.rb', line 7

def condition
  @condition
end

#entitiesObject (readonly)

Returns the value of attribute entities.



9
10
11
# File 'lib/autotask_api/entity_collection.rb', line 9

def entities
  @entities
end

Instance Method Details

#each(&block) ⇒ Object



18
19
20
# File 'lib/autotask_api/entity_collection.rb', line 18

def each(&block)
  entities.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/autotask_api/entity_collection.rb', line 41

def empty?
  entities.empty?
end

#last(&block) ⇒ Object



22
23
24
# File 'lib/autotask_api/entity_collection.rb', line 22

def last(&block)
  entities.last(&block)
end

#next_pageObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/autotask_api/entity_collection.rb', line 30

def next_page
  new_expression = Expression.new('id', 'GreaterThan', entities.last[:id])

  condition.remove_expression_by_field('id')
  params = condition.expressions.empty? ? new_expression : [condition, new_expression]

  new_condition = Condition.new(params)

  class_name.where(new_condition, client)
end

#next_page?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/autotask_api/entity_collection.rb', line 26

def next_page?
  entities.size >= PAGE_SIZE
end