Class: CouchScheduler::Map

Inherits:
Object
  • Object
show all
Includes:
CouchView::Map
Defined in:
lib/couch_scheduler/map.rb

Instance Method Summary collapse

Instance Method Details

#mapObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/couch_scheduler/map.rb', line 5

def map
  %{
    function(doc){
      if (#{conditions}){
        if (doc.start){
          startDate = doc.start.replace(/-/g, '/')
          var start = new Date(startDate)
        } else {
          var start = new Date()
        }

        if (doc.end){
          endDate = doc.end.replace(/-/g, '/')
          var end = new Date(endDate)
        } else {
          var end = new Date("2025/01/01")
        }
        
        while(start < end){
          year  = start.getFullYear()
          
          month = start.getMonth() + 1
          if (month < 10)
            month = "0" + month.toString()
          
          day  = start.getDate()
          if (day < 10)
            day = "0" + day.toString()

          emit(
            year + "-" + 
            month + "-" + 
            day, 
            null
          );
          start.setDate(start.getDate() + 1)
        }
      }
    }
  }
end