Class: Uberbringer::QueryBase

Inherits:
Array
  • Object
show all
Includes:
DateHelper
Defined in:
lib/uberbringer/query_base.rb

Constant Summary collapse

FIELD_MAPPINGS =
{
    :status => 'Status',
    :submit_date => 'Submit Date',
    :group => 'Assigned Group'
}
STATUS_MAPPINGS =
{
    :pending => 'Pending',
    :assigned => 'Assigned',
    :new => 'New',
    :in_progress => 'In Progress',
    :closed => 'Closed',
    :resolved => 'Resolved'
}
OPERATORS =
{
    :greater_than => '>',
    :less_than => '<',
    :not_equal_to => '!=',
    :equal_to => '='
}

Instance Method Summary collapse

Methods included from DateHelper

#sunday_before_last, #this_past_sunday, #today

Instance Method Details

#all_closed_ticketsObject



31
32
33
# File 'lib/uberbringer/query_base.rb', line 31

def all_closed_tickets
  filter_by_status([STATUS_MAPPINGS[:closed],STATUS_MAPPINGS[:resolved]])
end

#all_open_ticketsObject



27
28
29
# File 'lib/uberbringer/query_base.rb', line 27

def all_open_tickets
  filter_by_status([STATUS_MAPPINGS[:pending],STATUS_MAPPINGS[:assigned],STATUS_MAPPINGS[:new],STATUS_MAPPINGS[:in_progress]])
end

#for_group(group) ⇒ Object



52
53
54
# File 'lib/uberbringer/query_base.rb', line 52

def for_group(group)
  self << {:field => FIELD_MAPPINGS[:group], :value => group}
end

#last_weekObject



43
44
45
46
# File 'lib/uberbringer/query_base.rb', line 43

def last_week
  self << {:field => FIELD_MAPPINGS[:submit_date], :value => date_format(sunday_before_last), :operator => OPERATORS[:greater_than]}
  self << {:field => FIELD_MAPPINGS[:submit_date], :value => date_format(this_past_sunday), :operator => OPERATORS[:less_than]}
end

#older_than(number_of_days) ⇒ Object



35
36
37
# File 'lib/uberbringer/query_base.rb', line 35

def older_than(number_of_days)
  self << {:field => FIELD_MAPPINGS[:submit_date], :value => date_format(Date.today - number_of_days), :operator => OPERATORS[:less_than]}
end

#submitted_todayObject



48
49
50
# File 'lib/uberbringer/query_base.rb', line 48

def 
  self << {:field => FIELD_MAPPINGS[:submit_date], :value => date_format(today), :operator => OPERATORS[:greater_than]}
end

#this_weekObject



39
40
41
# File 'lib/uberbringer/query_base.rb', line 39

def this_week
  self << {:field => FIELD_MAPPINGS[:submit_date], :value => date_format(this_past_sunday), :operator => OPERATORS[:greater_than]}
end

#with_status(status) ⇒ Object

Raises:

  • (ArgumentError)


56
57
58
59
# File 'lib/uberbringer/query_base.rb', line 56

def with_status(status)
  raise ArgumentError unless status.kind_of?(Array)
  filter_by_status(map_status(status))
end

#without_status(status) ⇒ Object

Raises:

  • (ArgumentError)


61
62
63
64
# File 'lib/uberbringer/query_base.rb', line 61

def without_status(status)
  raise ArgumentError unless status.kind_of?(Array)
  filter_by_status(map_status(status),OPERATORS[:not_equal_to])
end