mocal 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/bin/mocal +5 -0
- data/lib/mocal.rb +110 -0
- data/lib/mocal/highlite.rb +20 -0
- data/lib/mocal/holiday.rb +18 -0
- data/lib/mocal/version.rb +3 -0
- data/mocal.gemspec +20 -0
- data/spec/mocal_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14b790b2b7cc7100a514967bfbee1aa497f65e4c
|
4
|
+
data.tar.gz: fefdf5479f3646c81ea14456e5b77b8cea733989
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25c42f27af2cde8a3fe20eb8513c3871331368a5331f6ec7805bad9a4c1e6ea417a71752437f83b42edbb7204abb931c93aad56557746208f5a7d49af64e45dd
|
7
|
+
data.tar.gz: 215af84631b5407c0d3a5ad47bcb5e8d3c6c85b2399a1ebace88536580ed623708e2c72958ce10f2fbbb9deb725d7f11d3c108c60f45881b59e112580cab45a6
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 YANO Satoru
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/mocal
ADDED
data/lib/mocal.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require "date"
|
5
|
+
require "mocal/version"
|
6
|
+
require "mocal/holiday"
|
7
|
+
require "mocal/highlite"
|
8
|
+
require "json"
|
9
|
+
|
10
|
+
module Mocal
|
11
|
+
class << self
|
12
|
+
def terminal_width
|
13
|
+
%x(stty size).split.map(&:to_i)[1]
|
14
|
+
end
|
15
|
+
|
16
|
+
def config_json
|
17
|
+
@config_json ||= open(File.expand_path("~/.mocal.json")) do |io|
|
18
|
+
JSON.load(io)
|
19
|
+
end rescue {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def offdays
|
23
|
+
offday = []
|
24
|
+
json_data = config_json["offday"] || config_json["offdays"] || {}
|
25
|
+
json_data.keys.each do |k|
|
26
|
+
json_data[k].each do |d|
|
27
|
+
offday << "#{k}-#{d}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
offday
|
31
|
+
end
|
32
|
+
|
33
|
+
def user_offday?(day)
|
34
|
+
@user_offdays ||= offdays
|
35
|
+
@user_offdays.include?(day.to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_cal(cal, label=false)
|
39
|
+
today = Date.today
|
40
|
+
first = Date.new(cal.year, cal.month, 1)
|
41
|
+
last = first.next_month - 1
|
42
|
+
buf = Array.new(8, "")
|
43
|
+
# buf[0] = "#{'%2d' % cal.month}月 #{cal.year if label}".center(20) + " "
|
44
|
+
# buf[1] = "月 火 水 木 金 土 日 "
|
45
|
+
buf[0] = "#{cal.strftime('%B')} #{cal.year if label}".center(21) + " "
|
46
|
+
buf[1] = "Mo Tu We Th Fr Sa Su "
|
47
|
+
|
48
|
+
i = 2
|
49
|
+
buf[i] = " " * ((first.wday+6)%7)
|
50
|
+
(first..last).each do |d|
|
51
|
+
_day = "%2d" % d.day
|
52
|
+
if STDOUT.isatty
|
53
|
+
_day = _day.bright.underscore if d.holiday? || user_offday?(d)
|
54
|
+
_day = _day.reverse if d == today
|
55
|
+
end
|
56
|
+
buf[i] += "#{_day} "
|
57
|
+
if d.sunday?
|
58
|
+
buf[i] += " "
|
59
|
+
i += 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
buf[i] += " " * (7 - last.wday) + " "
|
63
|
+
(i+1..7).each do |j|
|
64
|
+
buf[j] = " " * 22
|
65
|
+
end
|
66
|
+
buf#.map{|b| b+"|"}
|
67
|
+
end
|
68
|
+
|
69
|
+
def print_month(year, month)
|
70
|
+
print_n_months(year, month, 1, true)
|
71
|
+
end
|
72
|
+
|
73
|
+
def print_n_months(year, month, n=3, label=false)
|
74
|
+
cal = Date.new(year, month, 1)
|
75
|
+
m = []
|
76
|
+
n.times do |i|
|
77
|
+
m << build_cal(cal, label)
|
78
|
+
cal = cal.next_month
|
79
|
+
end
|
80
|
+
8.times do |i|
|
81
|
+
n.times {|j| print m[j][i] }
|
82
|
+
print "\n"
|
83
|
+
end
|
84
|
+
print "\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
def print_year(year)
|
88
|
+
col = [4, terminal_width/22].min
|
89
|
+
puts "[ #{ARGV[0]} ]".center(col*22-2)
|
90
|
+
(12/col).times {|m| print_n_months(year, m*col+1, col) }
|
91
|
+
end
|
92
|
+
|
93
|
+
def run(_argv)
|
94
|
+
case _argv.size
|
95
|
+
when 0
|
96
|
+
today = Date.today.prev_month
|
97
|
+
print_n_months(today.year, today.month, 3, true)
|
98
|
+
when 1
|
99
|
+
argv = _argv[0].to_i
|
100
|
+
if argv <= 12
|
101
|
+
print_month(Date.today.year, argv)
|
102
|
+
else
|
103
|
+
print_year(argv)
|
104
|
+
end
|
105
|
+
else
|
106
|
+
print_month(_argv[1].to_i, _argv[0].to_i)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
class String
|
5
|
+
def escape(code)
|
6
|
+
"\e[#{code}m#{self}\e[0m"
|
7
|
+
end
|
8
|
+
def bright
|
9
|
+
escape 1
|
10
|
+
end
|
11
|
+
def underscore
|
12
|
+
escape 4
|
13
|
+
end
|
14
|
+
def blink
|
15
|
+
escape 5
|
16
|
+
end
|
17
|
+
def reverse
|
18
|
+
escape 7
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
class Date
|
7
|
+
Offdays = [
|
8
|
+
# 2014
|
9
|
+
'2014-01-01', '2014-01-13', '2014-02-11', '2014-03-21',
|
10
|
+
'2014-04-29', '2014-05-05', '2014-05-06', '2014-07-21',
|
11
|
+
'2014-09-15', '2014-09-23', '2014-10-13', '2014-11-03',
|
12
|
+
'2014-11-24', '2014-12-23',
|
13
|
+
]
|
14
|
+
|
15
|
+
def holiday?
|
16
|
+
saturday? || sunday? || Offdays.include?(self.to_s)
|
17
|
+
end
|
18
|
+
end
|
data/mocal.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mocal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mocal"
|
8
|
+
spec.version = Mocal::VERSION
|
9
|
+
spec.authors = ["YANO Satoru"]
|
10
|
+
spec.email = ["satoru@yanonet.com"]
|
11
|
+
spec.description = %q{displays a calendar}
|
12
|
+
spec.summary = %q{alternative cal command}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
end
|
data/spec/mocal_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mocal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- YANO Satoru
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: displays a calendar
|
14
|
+
email:
|
15
|
+
- satoru@yanonet.com
|
16
|
+
executables:
|
17
|
+
- mocal
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/mocal
|
27
|
+
- lib/mocal.rb
|
28
|
+
- lib/mocal/highlite.rb
|
29
|
+
- lib/mocal/holiday.rb
|
30
|
+
- lib/mocal/version.rb
|
31
|
+
- mocal.gemspec
|
32
|
+
- spec/mocal_spec.rb
|
33
|
+
- spec/spec_helper.rb
|
34
|
+
homepage: ''
|
35
|
+
licenses:
|
36
|
+
- MIT
|
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
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.3.0
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: alternative cal command
|
58
|
+
test_files:
|
59
|
+
- spec/mocal_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
has_rdoc:
|