Class: PolyrexCalendar
- Inherits:
-
PolyrexCalendarBase
- Object
- PolyrexCalendarBase
- PolyrexCalendar
- Defined in:
- lib/polyrex-calendar.rb
Instance Method Summary collapse
-
#initialize(calendar_file = nil, options = {}) ⇒ 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, options = {}) ⇒ PolyrexCalendar
Returns a new instance of PolyrexCalendar.
67 68 69 70 71 72 73 74 |
# File 'lib/polyrex-calendar.rb', line 67 def initialize(calendar_file=nil, ={}) super(calendar_file, ) @xsl = fetch_file 'calendar.xsl' @css = fetch_file 'layout.css' end |
Instance Method Details
#inspect ⇒ Object
76 77 78 |
# File 'lib/polyrex-calendar.rb', line 76 def inspect() %Q(=> #<PolyrexCalendar:#{self.object_id} @id="#{@id}", @year="#{@year}">) end |
#kitchen_planner ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/polyrex-calendar.rb', line 80 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
119 120 121 122 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 |
# File 'lib/polyrex-calendar.rb', line 119 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(8 - wday) + a end r end pxmonth.xslt = 'month_calendar.xsl' pxmonth.css_layout = 'month_layout.css' pxmonth.css_style = 'month.css' pxmonth end end |
#this_month ⇒ Object
192 193 194 |
# File 'lib/polyrex-calendar.rb', line 192 def this_month() self.month(DateTime.now.month) end |
#this_week ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/polyrex-calendar.rb', line 177 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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/polyrex-calendar.rb', line 98 def year_planner() px = Polyrex.new(@visual_schema, id_counter: @id) px.summary.year = @year (1..12).each {|n| px.add self.month(n, monday_week: true) } # 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.css_layout = 'layout.css' px.css_style = 'year.css' px.filename = px.summary.year.to_s + '-planner.html' px end |