Class: ReportFilter

Inherits:
Object
  • Object
show all
Defined in:
app/models/report_filter.rb

Direct Known Subclasses

WorksReportFilter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ReportFilter

Returns a new instance of ReportFilter.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/report_filter.rb', line 7

def initialize(attributes)
  date = Date.today - 5
  @start_on = Date.civil(date.year, date.month, 01)
  @end_on   = Date.civil(date.year, date.month, -1)
  @page_size = 1000

  if attributes
    attributes = attributes.clone
    
    start_on_param = attributes.delete(:start_on)
    @start_on = Date.parse(start_on_param) if start_on_param && start_on_param.size > 0
    
    end_on_param = attributes.delete(:end_on)
    @end_on = Date.parse(end_on_param) if end_on_param && end_on_param.size > 0
    
    page_size_param = attributes.delete(:page_size)
    @page_size = page_size_param.to_i if page_size_param.to_i > 0
    
    raise "Unknown parameters: #{attributes.inspect}" unless attributes.empty?
  end
end

Instance Attribute Details

#end_onObject (readonly)

Returns the value of attribute end_on.



4
5
6
# File 'app/models/report_filter.rb', line 4

def end_on
  @end_on
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



5
6
7
# File 'app/models/report_filter.rb', line 5

def page_size
  @page_size
end

#start_onObject (readonly)

Returns the value of attribute start_on.



3
4
5
# File 'app/models/report_filter.rb', line 3

def start_on
  @start_on
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'app/models/report_filter.rb', line 2

def title
  @title
end