gmuday 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/gmuday.rb +112 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7ae6165b5a82c64f2ed99839435ffccccdae476e91ffb2aff3fdfdb96b8ecd12
|
4
|
+
data.tar.gz: ce0a1b30c5ff74d85a990fbd8850ca0318682739497f9387bb4219321495b825
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d07d2f4bc252cd091e03f823e1cb8e7fc677c11aeb51fe7265415843b42e4651e7271f9105095e9e21d4605a8992502f608a58551ed63d8488e0ee51a8fa829
|
7
|
+
data.tar.gz: d2ee1cb26ff9cb293c109d3f2a2ee7375b2db91ad64719923ecc95ac28445ebc39b80d2dbe7f1c03407f9ec8f15a68ecd01e5d512eb5e4c13a087ee73d048d63
|
data/lib/gmuday.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
#/usr/bin/ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'creek'
|
6
|
+
|
7
|
+
module GmuDay
|
8
|
+
|
9
|
+
def self.parse(file, myclass, day_start, day_end)
|
10
|
+
today = self.getToday
|
11
|
+
creek = Creek::Book.new "#{file}"
|
12
|
+
@sheet = creek.sheets[0]
|
13
|
+
|
14
|
+
days = self.getDays(day_start, day_end)
|
15
|
+
lineDay = Array.new
|
16
|
+
|
17
|
+
@sheet.simple_rows.each do |row|
|
18
|
+
break if "#{row['A']}" == self.calDay(days[-1], 1)
|
19
|
+
_class = row['G']
|
20
|
+
_day = row['A']
|
21
|
+
if addOrNot(myclass, _class, days, _day)
|
22
|
+
lineDay << row
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return lineDay
|
26
|
+
end
|
27
|
+
def self.addOrNot(_myclass, _class, _days, _day)
|
28
|
+
if _myclass.is_a? Array
|
29
|
+
return false unless _myclass.include?(_class) && _days.include?(_day)
|
30
|
+
return true
|
31
|
+
elsif _myclass.is_a? String
|
32
|
+
return false unless _class == _myclass && _days.include?(_day)
|
33
|
+
return true
|
34
|
+
else
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.course(_file, _myclass, hi_class=[], _day_start, _day_end)
|
40
|
+
lessons = self.parse(_file, _myclass, _day_start, _day_end)
|
41
|
+
|
42
|
+
puts "#{'节数'.rjust(28)} #{'课程'.rjust(13)} #{'班级'.rjust(34)} #{'教室'.rjust(12)}"
|
43
|
+
lessons.each do |lesson|
|
44
|
+
_week_raw = "#{lesson['C']}"
|
45
|
+
_week = self.week(_week_raw[0].to_i)
|
46
|
+
_ltime = _week_raw.reverse
|
47
|
+
_ltime.chop!
|
48
|
+
ltime = _ltime.reverse
|
49
|
+
_lesson_raw = "#{lesson['F']}"
|
50
|
+
_lesson = _lesson_raw.gsub(/\s+/, '')
|
51
|
+
_class = "#{lesson['G']}"
|
52
|
+
_classroom = lesson['H']
|
53
|
+
msg = "[ #{lesson['A']} ] #{_week} #{ltime.ljust(9)} #{_lesson.ljust(20, "一")} #{_class.ljust(12)} #{_classroom.ljust(16)}"
|
54
|
+
puts classInc(hi_class, _class) ? "\033[1;32m%s\033[0m" % msg : msg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
def self.classInc(_hi_class, _class)
|
58
|
+
if _hi_class.is_a? Array
|
59
|
+
return false unless _hi_class.include?(_class)
|
60
|
+
return true
|
61
|
+
elsif _hi_class.is_a? String
|
62
|
+
return false unless _class == _hi_class
|
63
|
+
return true
|
64
|
+
else
|
65
|
+
return false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
#private :classInc
|
69
|
+
def self.week(str)
|
70
|
+
case str
|
71
|
+
when 1
|
72
|
+
return "星期一"
|
73
|
+
when 2
|
74
|
+
return "星期二"
|
75
|
+
when 3
|
76
|
+
return "星期三"
|
77
|
+
when 4
|
78
|
+
return "星期四"
|
79
|
+
when 5
|
80
|
+
return "星期五"
|
81
|
+
when 6
|
82
|
+
return "星期六"
|
83
|
+
when 7
|
84
|
+
return "星期天"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
def self.getToday()
|
88
|
+
t = Time.new
|
89
|
+
return t.strftime("%Y-%m-%d")
|
90
|
+
end
|
91
|
+
def self.calDay(init_day=nil, int_num)
|
92
|
+
if init_day.is_a? NilClass
|
93
|
+
initDay = Time.new
|
94
|
+
else
|
95
|
+
init_day_arr = init_day.split("-")
|
96
|
+
initDay = Time.local(*init_day_arr)
|
97
|
+
end
|
98
|
+
past_future = initDay + 86400 * (int_num)
|
99
|
+
return past_future.strftime("%Y-%m-%d")
|
100
|
+
end
|
101
|
+
def self.getDays(_start=0, _end)
|
102
|
+
raise "ensure start < end" if _start > _end
|
103
|
+
return Array(GmuDay.calDay(_start)..GmuDay.calDay(_end))
|
104
|
+
end
|
105
|
+
def self.indexDay(_start_day, _end_day)
|
106
|
+
_start_day_arr = _start_day.split("-")
|
107
|
+
_end_day_arr = _end_day.split("-")
|
108
|
+
startDay = Time.local(*_start_day_arr)
|
109
|
+
endDay = Time.local(*_end_day_arr)
|
110
|
+
return ((endDay - startDay) / 86400).to_i
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gmuday
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sirius2
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: creek
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.0
|
27
|
+
description: GMU course helper
|
28
|
+
email: xjy37-me@outlook.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/gmuday.rb
|
34
|
+
homepage: https://gitee.com/Sirius2/gmuday
|
35
|
+
licenses:
|
36
|
+
- GPL-3.0+
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.2.3
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: GmuDay
|
57
|
+
test_files: []
|