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',
    :closed_date => 'Closed Date'
}
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



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

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

#all_open_ticketsObject



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

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

#closed_last_weekObject



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

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

#closed_this_weekObject



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

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

#closed_within_days(number_of_days = 7) ⇒ Object



67
68
69
# File 'lib/uberbringer/query_base.rb', line 67

def closed_within_days(number_of_days = 7)
  self << {:field => FIELD_MAPPINGS[:closed_date], :value => date_format(Date.today - number_of_days), :operator => OPERATORS[:greater_than]}
end

#for_group(group) ⇒ Object



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

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

#older_than(number_of_days) ⇒ Object



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

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



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

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

#with_status(status) ⇒ Object

Raises:

  • (ArgumentError)


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

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

#without_status(status) ⇒ Object

Raises:

  • (ArgumentError)


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

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