Class: PolyrexCalendar
- Inherits:
-
PolyrexCalendarBase
- Object
- PolyrexCalendarBase
- PolyrexCalendar
- Defined in:
- lib/polyrex-calendar.rb
Instance Method Summary collapse
-
#initialize(calendar_file = nil, year: nil, debug: false) ⇒ PolyrexCalendar
constructor
A new instance of PolyrexCalendar.
- #inspect ⇒ Object
- #kitchen_planner ⇒ Object
- #month(m, monday_week: false) ⇒ Object
- #save(planner_name, xslt: nil) ⇒ Object
- #this_month ⇒ Object
- #this_week ⇒ Object
- #year_planner ⇒ Object
Constructor Details
#initialize(calendar_file = nil, year: nil, debug: false) ⇒ PolyrexCalendar
Returns a new instance of PolyrexCalendar.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/polyrex-calendar.rb', line 59 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
#inspect ⇒ Object
77 78 79 |
# File 'lib/polyrex-calendar.rb', line 77 def inspect() %Q(=> #<PolyrexCalendar:#{self.object_id} @id="#{@id}", @year="#{@year}">) end |
#kitchen_planner ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/polyrex-calendar.rb', line 81 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
123 124 125 126 127 128 129 130 131 132 133 134 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 |
# File 'lib/polyrex-calendar.rb', line 123 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
182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/polyrex-calendar.rb', line 182 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_month ⇒ Object
209 210 211 |
# File 'lib/polyrex-calendar.rb', line 209 def this_month() self.month(DateTime.now.month) end |
#this_week ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/polyrex-calendar.rb', line 194 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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/polyrex-calendar.rb', line 99 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 |