xcal 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 381a7242d8cc072c67ca700f455f96a7ce793d5e
4
+ data.tar.gz: da3ccee9b1e44f40e3b56a54ca5cc313e7fcdf5b
5
+ SHA512:
6
+ metadata.gz: 37fd55ddc8f6e0b79685bd2e0320bb025ce9f9bdfd2a008b5c39c573107eeea0e73e6d32e48b5071aa7565e864382de72038afa6e43a747557e61eaa38e3d96d
7
+ data.tar.gz: 3544167b6037474f8e0da456e000775b76f195d439f67fec8e4cd34f2715ea0aeed4af7df36988e83cf6dd032860e98764727c4d141b7788a170f69ded909239
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xcal.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 xmisao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ xcal
2
+ ====
3
+
4
+ xcalは日本の祝日に対応したcal, ncalライクなカレンダーコマンドです。
5
+ 祝日の情報はGoogleが提供するiCalを利用し、表示のたびにダウンロードします。
6
+ カレンダーはカラフルに土曜日が青色、日曜日と祝日が赤色で表示されます。
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "xcal"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -2,5 +2,6 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'xcal'
5
+ include Xcal
5
6
 
6
7
  main()
@@ -2,135 +2,5 @@ require 'date'
2
2
  require 'open-uri'
3
3
  require 'icalendar'
4
4
 
5
- BLUE = "\e[34m"
6
- RED = "\e[31m"
7
- REVERSE = "\e[7m"
8
- CLEAR = "\e[0m"
9
-
10
- def red(str)
11
- RED + str + CLEAR
12
- end
13
-
14
- def blue(str)
15
- BLUE + str + CLEAR
16
- end
17
-
18
- def reverse(str)
19
- REVERSE + str + CLEAR
20
- end
21
-
22
- URL = 'https://www.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics'
23
-
24
- MONTH_TEMPLATE = [
25
- " January % ",
26
- " February % ",
27
- " March % ",
28
- " April % ",
29
- " May % ",
30
- " June % ",
31
- " July % ",
32
- " August % ",
33
- " September % ",
34
- " October % ",
35
- " November % ",
36
- " December % "
37
- ]
38
-
39
- MONTH_DAY = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
40
-
41
- ROWS = 6
42
- WEEK = 7
43
- MONTH = 3
44
- SPACE = 2
45
- HEADER = [red('Su'), 'Mo', 'Tu', 'We', 'Th', 'Fr', blue('Sa')]
46
-
47
- def get_japan_holidays()
48
- holidays = {}
49
- ical = open(URL){|f| f.read}
50
- cals = Icalendar.parse(ical)
51
- cals.each{|cal|
52
- cal.events.each{|event|
53
- start = event.dtstart
54
-
55
- y = start.year
56
- m = start.month
57
- d = start.day
58
-
59
- holidays[y] = {} unless holidays[y]
60
- holidays[y][m] = {} unless holidays[y][m]
61
- holidays[y][m][d] = true
62
- }
63
- }
64
-
65
- holidays
66
- end
67
-
68
- def fill_calendar(year, month, table, month_offset, holidays, today)
69
- offset = Date.new(year, month, 1).wday - 1
70
- month_day = get_month_day(year, month)
71
- (1..month_day).each{|d|
72
- date = Date.new(year, month, d)
73
-
74
- day = sprintf('%2d', d)
75
- if is_holiday?(year, month, d, holidays)
76
- day = red(day)
77
- elsif date.wday == 6
78
- day = blue(day)
79
- elsif date.wday == 0
80
- day = red(day)
81
- end
82
-
83
- if today == date
84
- day = reverse(day)
85
- end
86
-
87
- table[(offset + d) / 7][month_offset + date.wday] = day
88
- }
89
- end
90
-
91
- def is_holiday?(y, m, d, holidays)
92
- holidays[y] and holidays[y][m] and holidays[y][m][d]
93
- end
94
-
95
- def month_header(y, m)
96
- MONTH_TEMPLATE[m - 1].sub('%', sprintf('%4d', y))
97
- end
98
-
99
- def get_month_day(y, m)
100
- day = MONTH_DAY[m - 1]
101
- if m == 2 and Date.leap?(y)
102
- day += 1
103
- end
104
- day
105
- end
106
-
107
- def main()
108
- japan_holidays = get_japan_holidays()
109
-
110
- table = Array.new(ROWS){
111
- Array.new(WEEK * MONTH + SPACE){|i|
112
- (i + 1) % 8 == 0 ? '' : ' '
113
- }
114
- }
115
-
116
- today = Date.today
117
- last_month = today << 1
118
- next_month = today >> 1
119
-
120
- fill_calendar(last_month.year, last_month.month, table, 0, japan_holidays, today)
121
- fill_calendar(today.year, today.month, table, 8, japan_holidays, today)
122
- fill_calendar(next_month.year, next_month.month, table, 16, japan_holidays, today)
123
-
124
- month_headers = [
125
- month_header(last_month.year, last_month.month),
126
- month_header(today.year, today.month),
127
- month_header(next_month.year, next_month.month)
128
- ]
129
- puts month_headers.join(' ')
130
-
131
- puts HEADER.join(' ') + ' ' + HEADER.join(' ') + ' ' + HEADER.join(' ')
132
-
133
- table.each{|row|
134
- puts row.join(' ')
135
- }
136
- end
5
+ require "xcal/version"
6
+ require "xcal/xcal"
@@ -0,0 +1,3 @@
1
+ module Xcal
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,137 @@
1
+ module Xcal
2
+ BLUE = "\e[34m"
3
+ RED = "\e[31m"
4
+ REVERSE = "\e[7m"
5
+ CLEAR = "\e[0m"
6
+
7
+ def red(str)
8
+ RED + str + CLEAR
9
+ end
10
+
11
+ def blue(str)
12
+ BLUE + str + CLEAR
13
+ end
14
+
15
+ def reverse(str)
16
+ REVERSE + str + CLEAR
17
+ end
18
+
19
+ URL = 'https://www.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics'
20
+
21
+ MONTH_TEMPLATE = [
22
+ " January % ",
23
+ " February % ",
24
+ " March % ",
25
+ " April % ",
26
+ " May % ",
27
+ " June % ",
28
+ " July % ",
29
+ " August % ",
30
+ " September % ",
31
+ " October % ",
32
+ " November % ",
33
+ " December % "
34
+ ]
35
+
36
+ MONTH_DAY = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
37
+
38
+ ROWS = 6
39
+ WEEK = 7
40
+ MONTH = 3
41
+ SPACE = 2
42
+
43
+ def header
44
+ [red('Su'), 'Mo', 'Tu', 'We', 'Th', 'Fr', blue('Sa')]
45
+ end
46
+
47
+ def get_japan_holidays()
48
+ holidays = {}
49
+ ical = open(URL){|f| f.read}
50
+ cals = Icalendar::Calendar.parse(ical)
51
+ cals.each{|cal|
52
+ cal.events.each{|event|
53
+ start = event.dtstart
54
+
55
+ y = start.year
56
+ m = start.month
57
+ d = start.day
58
+
59
+ holidays[y] = {} unless holidays[y]
60
+ holidays[y][m] = {} unless holidays[y][m]
61
+ holidays[y][m][d] = true
62
+ }
63
+ }
64
+
65
+ holidays
66
+ end
67
+
68
+ def fill_calendar(year, month, table, month_offset, holidays, today)
69
+ offset = Date.new(year, month, 1).wday - 1
70
+ month_day = get_month_day(year, month)
71
+ (1..month_day).each{|d|
72
+ date = Date.new(year, month, d)
73
+
74
+ day = sprintf('%2d', d)
75
+ if is_holiday?(year, month, d, holidays)
76
+ day = red(day)
77
+ elsif date.wday == 6
78
+ day = blue(day)
79
+ elsif date.wday == 0
80
+ day = red(day)
81
+ end
82
+
83
+ if today == date
84
+ day = reverse(day)
85
+ end
86
+
87
+ table[(offset + d) / 7][month_offset + date.wday] = day
88
+ }
89
+ end
90
+
91
+ def is_holiday?(y, m, d, holidays)
92
+ holidays[y] and holidays[y][m] and holidays[y][m][d]
93
+ end
94
+
95
+ def month_header(y, m)
96
+ MONTH_TEMPLATE[m - 1].sub('%', sprintf('%4d', y))
97
+ end
98
+
99
+ def get_month_day(y, m)
100
+ day = MONTH_DAY[m - 1]
101
+ if m == 2 and Date.leap?(y)
102
+ day += 1
103
+ end
104
+ day
105
+ end
106
+
107
+ def main()
108
+ japan_holidays = get_japan_holidays()
109
+
110
+ table = Array.new(ROWS){
111
+ Array.new(WEEK * MONTH + SPACE){|i|
112
+ (i + 1) % 8 == 0 ? '' : ' '
113
+ }
114
+ }
115
+
116
+ today = Date.today
117
+ last_month = today << 1
118
+ next_month = today >> 1
119
+
120
+ fill_calendar(last_month.year, last_month.month, table, 0, japan_holidays, today)
121
+ fill_calendar(today.year, today.month, table, 8, japan_holidays, today)
122
+ fill_calendar(next_month.year, next_month.month, table, 16, japan_holidays, today)
123
+
124
+ month_headers = [
125
+ month_header(last_month.year, last_month.month),
126
+ month_header(today.year, today.month),
127
+ month_header(next_month.year, next_month.month)
128
+ ]
129
+ puts month_headers.join(' ')
130
+
131
+ puts header.join(' ') + ' ' + header.join(' ') + ' ' + header.join(' ')
132
+
133
+ table.each{|row|
134
+ puts row.join(' ')
135
+ }
136
+ end
137
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xcal/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xcal"
8
+ spec.version = Xcal::VERSION
9
+ spec.authors = ["xmisao"]
10
+ spec.email = ["mail@xmisao.com"]
11
+
12
+ spec.summary = "xcal displays a japanese calendar"
13
+ spec.description = "xcal is a command line tool that displays japanese calendar like UNIX's `cal` command."
14
+ spec.homepage = 'https://github.com/xmisao/xcal'
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency("icalendar", "~> 2")
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ end
metadata CHANGED
@@ -1,63 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - xmisao
9
8
  autorequire:
10
- bindir: bin
9
+ bindir: exe
11
10
  cert_chain: []
12
- date: 2013-09-25 00:00:00.000000000 Z
11
+ date: 2017-06-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: icalendar
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: '2'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
30
- description: xcal displays a japan calendar like cal, ncal
31
- email: mail@xmisao.com
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: xcal is a command line tool that displays japanese calendar like UNIX's
70
+ `cal` command.
71
+ email:
72
+ - mail@xmisao.com
32
73
  executables:
33
74
  - xcal
34
75
  extensions: []
35
76
  extra_rdoc_files: []
36
77
  files:
37
- - bin/xcal
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exe/xcal
38
87
  - lib/xcal.rb
88
+ - lib/xcal/version.rb
89
+ - lib/xcal/xcal.rb
90
+ - xcal.gemspec
39
91
  homepage: https://github.com/xmisao/xcal
40
- licenses: []
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
41
95
  post_install_message:
42
96
  rdoc_options: []
43
97
  require_paths:
44
98
  - lib
45
99
  required_ruby_version: !ruby/object:Gem::Requirement
46
- none: false
47
100
  requirements:
48
- - - ! '>='
101
+ - - ">="
49
102
  - !ruby/object:Gem::Version
50
103
  version: '0'
51
104
  required_rubygems_version: !ruby/object:Gem::Requirement
52
- none: false
53
105
  requirements:
54
- - - ! '>='
106
+ - - ">="
55
107
  - !ruby/object:Gem::Version
56
108
  version: '0'
57
109
  requirements: []
58
110
  rubyforge_project:
59
- rubygems_version: 1.8.23
111
+ rubygems_version: 2.5.2
60
112
  signing_key:
61
- specification_version: 3
62
- summary: xcal displays a japan calendar like cal, ncal
113
+ specification_version: 4
114
+ summary: xcal displays a japanese calendar
63
115
  test_files: []