Class: NcsNavigator::Warehouse::Transformers::EventStartFromContactTransformer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ncs_navigator/warehouse/transformers/event_start_from_contact_transformer.rb

Overview

This transformer finds all events without start dates and attempts to set them from the earliest associated contact.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ EventStartFromContactTransformer

Returns a new instance of EventStartFromContactTransformer.



15
16
17
# File 'lib/ncs_navigator/warehouse/transformers/event_start_from_contact_transformer.rb', line 15

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



11
12
13
# File 'lib/ncs_navigator/warehouse/transformers/event_start_from_contact_transformer.rb', line 11

def configuration
  @configuration
end

Instance Method Details

#transform(status)

This method returns an undefined value.

Implements this transformer's behavior.

Parameters:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ncs_navigator/warehouse/transformers/event_start_from_contact_transformer.rb', line 24

def transform(status)
  configuration.model(:Event).all(:event_start_date.like => '9%').each do |event|
    candidates = ::DataMapper.repository.adapter.select(%Q{
      SELECT c.contact_date, c.contact_start_time
      FROM link_contact lc INNER JOIN contact c ON lc.contact_id=c.contact_id
      WHERE lc.event_id='#{event.event_id}'
      ORDER BY c.contact_date, c.contact_start_time
    })

    start_date = candidates.
      select { |dt| dt.contact_date !~ /^9/ }.collect { |dt| dt.contact_date }.uniq.first
    start_time = candidates.
      select { |dt| dt.contact_date == start_date && dt.contact_start_time !~ /^9/ }.
      collect { |dt| dt.contact_start_time }.first

    if start_date || start_time
      event.event_start_date = start_date if start_date
      event.event_start_time = start_time if start_time

      save(event, status)

      status.record_count += 1
    end
  end
end