Class: ESA::ContextProviders::DateContextProvider

Inherits:
ESA::ContextProvider show all
Defined in:
lib/esa/context_providers/date_context_provider.rb

Class Method Summary collapse

Methods inherited from ESA::ContextProvider

check_subcontexts, contained_subcontexts, existing_subcontexts

Class Method Details

.contained_ids(context, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/esa/context_providers/date_context_provider.rb', line 12

def self.contained_ids(context, options = {})
  if options[:all].present? and options[:all] == true and
      context.effective_start_date.present? and
      context.effective_end_date.present?
    dates = context.effective_start_date..context.effective_end_date
  else
    dates = context.transactions.uniq.pluck("date(esa_transactions.time)").sort
  end

  if options[:period].present? and options[:period] == :month
    dates.group_by{|d| [d.year, d.month]}.keys.
    map do |year,month|
      start_date = Date.new(year, month, 1)
      end_date = start_date.end_of_month
      [start_date, end_date]
    end
  else
    dates.zip dates
  end
end

.context_id(context, options = {}) ⇒ Object



8
9
10
# File 'lib/esa/context_providers/date_context_provider.rb', line 8

def self.context_id(context, options = {})
  [context.start_date, context.end_date]
end

.instantiate(parent, namespace, id, options = {}) ⇒ Object



33
34
35
36
# File 'lib/esa/context_providers/date_context_provider.rb', line 33

def self.instantiate(parent, namespace, id, options = {})
  start_date, end_date = id
  ESA::Contexts::DateContext.new(chart_id: parent.chart_id, parent_id: parent.id, namespace: namespace, start_date: start_date, end_date: end_date)
end

.provided_typesObject



4
5
6
# File 'lib/esa/context_providers/date_context_provider.rb', line 4

def self.provided_types
  ["ESA::Contexts::DateContext"]
end