Class: PolyrexCalendar
- Inherits:
-
PolyrexCalendarBase
- Object
- PolyrexCalendarBase
- PolyrexCalendar
- Defined in:
- lib/polyrex-calendar.rb
Instance Method Summary collapse
-
#initialize(calendar_file = nil, year: Date.today.year.to_s) ⇒ PolyrexCalendar
constructor
A new instance of PolyrexCalendar.
- #inspect ⇒ Object
- #kitchen_planner ⇒ Object
- #month(m, monday_week: false) ⇒ Object
- #this_month ⇒ Object
- #this_week ⇒ Object
- #year_planner ⇒ Object
Constructor Details
#initialize(calendar_file = nil, year: Date.today.year.to_s) ⇒ PolyrexCalendar
Returns a new instance of PolyrexCalendar.
102 103 104 105 106 107 108 109 |
# File 'lib/polyrex-calendar.rb', line 102 def initialize(calendar_file=nil, year: Date.today.year.to_s) super(calendar_file, year: year) @xsl = fetch_file 'calendar.xsl' @css = fetch_file 'layout.css' end |
Instance Method Details
#inspect ⇒ Object
111 112 113 |
# File 'lib/polyrex-calendar.rb', line 111 def inspect() %Q(=> #<PolyrexCalendar:#{self.object_id} @id="#{@id}", @year="#{@year}">) end |
#kitchen_planner ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/polyrex-calendar.rb', line 115 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
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/polyrex-calendar.rb', line 157 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 |
#this_month ⇒ Object
231 232 233 |
# File 'lib/polyrex-calendar.rb', line 231 def this_month() self.month(DateTime.now.month) end |
#this_week ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/polyrex-calendar.rb', line 216 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_planner ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/polyrex-calendar.rb', line 133 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 |