Class: SharedWorkforce::TaskResult

Inherits:
Object
  • Object
show all
Defined in:
lib/shared_workforce/task_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ TaskResult

Returns a new instance of TaskResult.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shared_workforce/task_result.rb', line 10

def initialize(params)
  params = params.with_indifferent_access
  
  self.task_hash = if params[:task]
    params[:task]
  else
    params
  end
  
  @responses = TaskResponse.create_collection_from_array(task_hash[:responses]) if task_hash[:responses]
  self.name = callback_params[:_task][:class_name] if callback_params && callback_params[:_task] && callback_params[:_task][:class_name]
end

Instance Attribute Details

#callback_paramsObject (readonly)

Returns the value of attribute callback_params.



4
5
6
# File 'lib/shared_workforce/task_result.rb', line 4

def callback_params
  @callback_params
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/shared_workforce/task_result.rb', line 6

def name
  @name
end

#responsesObject

Returns the value of attribute responses.



5
6
7
# File 'lib/shared_workforce/task_result.rb', line 5

def responses
  @responses
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/shared_workforce/task_result.rb', line 7

def status
  @status
end

#task_hashObject

Returns the value of attribute task_hash.



8
9
10
# File 'lib/shared_workforce/task_result.rb', line 8

def task_hash
  @task_hash
end

Instance Method Details

#process!Object



35
36
37
38
39
40
41
# File 'lib/shared_workforce/task_result.rb', line 35

def process!
  if name && task = find_task(name)
    task.new(self)
  else
    raise TaskNotFound, "The task #{name} could not be found"
  end
end

#usernamesObject



31
32
33
# File 'lib/shared_workforce/task_result.rb', line 31

def usernames
  @responses.map(&:username).flatten
end