Module: GmuDay
- Defined in:
- lib/gmuday.rb
Class Method Summary collapse
- .addOrNot(_myclass, _class, _days, _day) ⇒ Object
- .buildBlock(rx, ry, rw, rh, ri, tc, tx, ty, ts, ti) ⇒ Object
- .calDay(init_day = nil, int_num) ⇒ Object
- .calWeek(i) ⇒ Object
- .classInc(_hi_class, _class) ⇒ Object
- .course(_file, _myclass, hi_class = [], _day_start, _day_end) ⇒ Object
- .flush(a, b, ele, m_down) ⇒ Object
- .fOrNot(a, b, ele) ⇒ Object
- .getDays(_start = 0, _end) ⇒ Object
- .getToday ⇒ Object
- .getWeekCourse(_file, _whichWeek, _cl) ⇒ Object
- .indexDay(_start_day, _end_day) ⇒ Object
- .parse(file, myclass, day_start, day_end) ⇒ Object
- .parse_week(course) ⇒ Object
- .show(file, whichWeek, cl, init_type = nil) ⇒ Object
-
.top ⇒ Object
Added.
- .tSplit(str) ⇒ Object
- .week(i) ⇒ Object
- .weekNum(str) ⇒ Object
Class Method Details
.addOrNot(_myclass, _class, _days, _day) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gmuday.rb', line 29 def self.addOrNot(_myclass, _class, _days, _day) if _myclass.is_a? Array return false unless _myclass.include?(_class) && _days.include?(_day) return true elsif _myclass.is_a? String return false unless _class == _myclass && _days.include?(_day) return true else return false end end |
.buildBlock(rx, ry, rw, rh, ri, tc, tx, ty, ts, ti) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/gmuday.rb', line 126 def self.buildBlock(rx, ry, rw, rh, ri, tc, tx, ty, ts, ti) Rectangle.new( x: rx, y: ry, width: rw, height: rh, color: 'random', z: ri ) Text.new( tc, x: tx, y: ty, size: ts, color: 'white', z: ti ) end |
.calDay(init_day = nil, int_num) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/gmuday.rb', line 96 def self.calDay(init_day=nil, int_num) if init_day.is_a? NilClass initDay = Time.new else init_day_arr = init_day.split("-") initDay = Time.local(*init_day_arr) end past_future = initDay + 86400 * (int_num) return past_future.strftime("%Y-%m-%d") end |
.calWeek(i) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/gmuday.rb', line 166 def self.calWeek(i) t = Time.new tWeek = t.wday tWeek = 7 if tWeek == 0 last = -1 * (tWeek - 1) + i * 7 future = 7 - tWeek + i * 7 return [tWeek, last, future] end |
.classInc(_hi_class, _class) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gmuday.rb', line 55 def self.classInc(_hi_class, _class) if _hi_class.is_a? Array return false unless _hi_class.include?(_class) return true elsif _hi_class.is_a? String return false unless _class == _hi_class return true else return false end end |
.course(_file, _myclass, hi_class = [], _day_start, _day_end) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gmuday.rb', line 41 def self.course(_file, _myclass, hi_class=[], _day_start, _day_end) lessons = self.parse(_file, _myclass, _day_start, _day_end) puts "#{'节数'.rjust(28)} #{'课程'.rjust(13)} #{'班级'.rjust(34)} #{'教室'.rjust(12)}" lessons.each do |lesson| spl = self.weekNum("#{lesson['C']}") _lesson_raw = "#{lesson['F']}" _lesson = _lesson_raw.gsub(/\s+/, '') _class = "#{lesson['G']}" _classroom = lesson['H'] msg = "[ #{lesson['A']} ] #{spl[1]} #{spl[2].ljust(9)} #{_lesson.ljust(20, "一")} #{_class.ljust(12)} #{_classroom.ljust(16)}" puts classInc(hi_class, _class) ? "\033[1;32m%s\033[0m" % msg : msg end end |
.flush(a, b, ele, m_down) ⇒ Object
210 211 212 213 214 |
# File 'lib/gmuday.rb', line 210 def self.flush(a, b, ele, m_down) t_raw = m_down % 2 == 0 ? ele[3] : ele[2] t_show = t_raw.length > 10 ? t_raw[0,10] : t_raw self.buildBlock((a -1)*150, b*50, 150, 50, 3 + m_down, t_show.center(20), (a -1)*150, 50/3 + b*50, 12, 4 + m_down) end |
.fOrNot(a, b, ele) ⇒ Object
205 206 207 208 209 |
# File 'lib/gmuday.rb', line 205 def self.fOrNot(a, b, ele) arr = ele[1] return true if ele.include?(a) && arr.include?(b) return false end |
.getDays(_start = 0, _end) ⇒ Object
106 107 108 109 |
# File 'lib/gmuday.rb', line 106 def self.getDays(_start=0, _end) raise "ensure start < end" if _start > _end return Array(GmuDay.calDay(_start)..GmuDay.calDay(_end)) end |
.getToday ⇒ Object
90 91 92 93 94 95 |
# File 'lib/gmuday.rb', line 90 def self.getToday() t = Time.new d = t.strftime("%Y-%m-%d") w = t.wday return [d, w] end |
.getWeekCourse(_file, _whichWeek, _cl) ⇒ Object
141 142 143 144 |
# File 'lib/gmuday.rb', line 141 def self.getWeekCourse(_file, _whichWeek, _cl) gmu_arr = self.calWeek(_whichWeek) return self.parse(_file, _cl, gmu_arr[1], gmu_arr[2]) end |
.indexDay(_start_day, _end_day) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/gmuday.rb', line 110 def self.indexDay(_start_day, _end_day) _start_day_arr = _start_day.split("-") _end_day_arr = _end_day.split("-") startDay = Time.local(*_start_day_arr) endDay = Time.local(*_end_day_arr) return ((endDay - startDay) / 86400).to_i end |
.parse(file, myclass, day_start, day_end) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gmuday.rb', line 10 def self.parse(file, myclass, day_start, day_end) today_r = self.getToday today = today_r[0] creek = Creek::Book.new "#{file}" @sheet = creek.sheets[0] days = self.getDays(day_start, day_end) lineDay = Array.new @sheet.simple_rows.each do |row| break if "#{row['A']}" == self.calDay(days[-1], 1) _class = row['G'] _day = row['A'] if addOrNot(myclass, _class, days, _day) lineDay << row end end return lineDay end |
.parse_week(course) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/gmuday.rb', line 175 def self.parse_week(course) #传入一天的course data #返回星期,课序,课程,地点。如1, [1,2], 课程, 地点 _t = course['C'] lesson = course['D'] arr = GmuDay.weekNum(_t) w = arr[0] t_raw = arr[2] t = self.tSplit(t_raw) wh = course['H'] if wh.include?('实验室') wh.gsub!('实验室','') wh.gsub!(/(|)/, '') end return [w, t, lesson, wh] end |
.show(file, whichWeek, cl, init_type = nil) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/gmuday.rb', line 145 def self.show(file, whichWeek, cl, init_type=nil) self.top() week = Array(0..6) $courses = self.getWeekCourse(file, whichWeek, cl) nW = 150 nH = 50 info = Array.new $courses.each do |course| info << self.parse_week(course) end info.each do |o| ol = o[1] l_raw = init_type == "w" ? o[3] : o[2] l_show = l_raw.length > 10 ? l_raw[0,10] : l_raw ol.each do |l| self.buildBlock((o[0] -1)*150, l*50, 150, 50, 1, l_show.center(20), (o[0] -1)*150, 50/3 + l*50, 12, 2) end end end |
.top ⇒ Object
Added
119 120 121 122 123 124 125 |
# File 'lib/gmuday.rb', line 119 def self.top() week = Array(0..6) week.each do |w| self.buildBlock(w*150, 0, 150, 50, 1, GmuDay.week(w+1), 150/3 + w*150, 50/3, 13, 2) end end |
.tSplit(str) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/gmuday.rb', line 191 def self.tSplit(str) # 传入Str,返回数组如第一第二节课(01020304),返回[1,2] str_len = str.length b_num = str_len /2 res_t = Array.new b_i = 0 until b_i*4+3 >= str_len do l_t_str = "#{str[b_i*4+2]}#{str[b_i*4+3]}" l_t = l_t_str.to_i res_t << l_t/2 b_i += 1 end return res_t end |
.week(i) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gmuday.rb', line 66 def self.week(i) case i when 1 return "星期一" when 2 return "星期二" when 3 return "星期三" when 4 return "星期四" when 5 return "星期五" when 6 return "星期六" when 7 return "星期天" end end |
.weekNum(str) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/gmuday.rb', line 84 def self.weekNum(str) str0 = str.reverse str1 = str0.chop! wInt = str[0].to_i return [wInt, self.week(wInt), str1.reverse] end |