Class: PolyrexCalendar

Inherits:
PolyrexCalendarBase
  • Object
show all
Defined in:
lib/polyrex-calendar.rb

Instance Method Summary collapse

Constructor Details

#initialize(calendar_file = nil, year: nil, debug: false) ⇒ PolyrexCalendar

Returns a new instance of PolyrexCalendar.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/polyrex-calendar.rb', line 71

def initialize(calendar_file=nil, year: nil, debug: false)
  
  @debug = debug
  
  year = if year.nil? then
    (Date.today.month > 6 ? Date.today.year + 1 : Date.today.year).to_s
  else
    year
  end

  puts ('year: ' + year.inspect).debug if debug
  super(calendar_file, year: year)

  @xsl = fetch_file 'calendar.xsl'
  @css = fetch_file 'layout.css'
     
end

Instance Method Details

#inspectObject



89
90
91
# File 'lib/polyrex-calendar.rb', line 89

def inspect()
   %Q(=> #<PolyrexCalendar:#{self.object_id} @id="#{@id}", @year="#{@year}">)
end

#kitchen_plannerObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/polyrex-calendar.rb', line 93

def kitchen_planner()

  px = @calendar

  # add a css selector for the current day
  date = DateTime.now.strftime("%Y-%b-%d")
  e = px.element("records/month/records/day/summary[sdate='#{date}']")
  e.attributes[:class] = 'selected' if e

  px.xslt = 'kplanner.xsl'
  px.css_layout = 'monthday_layout.css'
  px.css_style = 'monthday.css'
  px.filename = @year + '-kitchen-planner.html'

  px
  
end

#month(m, monday_week: false) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/polyrex-calendar.rb', line 135

def month(m, monday_week: false)

  if monday_week == true

    pxmonth = make_month(m) do |a, wday|

      # Monday start
      # wdays: 1 = Monday, 0 = Sunday

      r = case wday

        # the 1st day of the month is a Monday, add no placeholders
        when 1 then  a

        # the 1st day is a Sunday, add 6 placeholders before that day
        when 0 then Array.new(6) + a

        # add a few placeholders before the 1st day          
        else Array.new(wday - 1) + a
      end

      r

    end

    pxmonth.xslt = 'monthday_calendar.xsl'
    pxmonth.css_layout = 'monthday_layout.css'
    pxmonth.css_style = 'monthday.css'
    pxmonth

  else

    pxmonth = make_month(m) do |a, wday|


      # Sunday start
      # wdays: 1 = Monday, 0 = Sunday

      r = case wday

        # the 1st day of the month is a Sunday, add no placeholders
        when 0 then  a

        # add a few placeholders before the 1st day          
        else Array.new(wday) + a
      end

      r

    end

    pxmonth.xslt = 'lmonth.xsl'
    pxmonth.css_layout = 'month_layout.css'
    pxmonth.css_style = 'month.css'
    pxmonth
  end

end

#save(planner_name, xslt: nil) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
# File 'lib/polyrex-calendar.rb', line 194

def save(planner_name, xslt: nil)
  
  planner = self.kitchen_planner
  return unless planner

  planner.xslt = xslt if xslt
  h = planner.to_webpage
  h.each_pair {|filename, value| FileX.write filename, value }
  "saved %s" % File.join(Dir.pwd, h.keys.first.to_s)

end

#this_monthObject



221
222
223
# File 'lib/polyrex-calendar.rb', line 221

def this_month()
  self.month(DateTime.now.month)
end

#this_weekObject



206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/polyrex-calendar.rb', line 206

def this_week()

  dt = DateTime.now
  days = @calendar.month(dt.month).day

  r = days.find {|day| day.date.cweek == dt.cweek }    
  pxweek = PolyrexObjects::Week.new
  pxweek.mon = Date::MONTHNAMES[dt.month]
  pxweek.no = dt.cweek.to_s
  pxweek.label = ''
  days[days.index(r),7].each{|day| pxweek.add day }

  pxweek
end

#year_plannerObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/polyrex-calendar.rb', line 111

def year_planner()

  px = Calendar.new(@visual_schema, id_counter: @id)
  px.summary.year = @year

  (1..12).each do |n| 
    px.add self.month(n, monday_week: true) 
  end

  # add a css selector for the current day
  date = DateTime.now.strftime("%Y-%b-%d")
  e = px.element("records/month/records/week/records/day/" \
                                            + "summary[sdate='#{date}']")
  e.attributes[:class] = 'selected' if e

  px.xslt = self.fetch_filepath('calendar.xsl')
  px.css_layout = 'layout.css'
  px.css_style = 'year.css'
  px.filename = px.summary.year.to_s + '-planner.html'

  px
  
end