rubyshelltools 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/modules/calendar/calendar.rb +3 -46
- data/lib/modules/calendar/calendar_event.rb +1 -1
- data/lib/modules/calendar/calendar_helper.rb +56 -0
- data/lib/rst.rb +6 -5
- data/rst.rb +1 -1
- metadata +5 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 641f55c4735fc80402667b74f37d8d6b2b91684f
|
4
|
+
data.tar.gz: cce31a850e6ca5f17a5a5b63da41fdcaf3c0a144
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12b4f4292524d658a3587aa3535b288b43b27dce16ffb5d68c585dfa90fa3d7b98713ae30add0e36a3517d1934cf3b774b47be099485768cd2c352e6b06c8717
|
7
|
+
data.tar.gz: 7a2f0e78844f86bc2da5ad9d3c41b58daefc5b633cc11503fe17e538cf7db133ba57072adaf44e507292375d2c0ecfb73c9db5fcde55dbc970386f4fe9547c3a
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'modules/persistent/persistent'
|
3
|
-
|
3
|
+
require 'modules/calendar/calendar_helper'
|
4
4
|
module RST
|
5
5
|
|
6
6
|
# Calendar-module provides the Calendar-class which is supposed to hold
|
@@ -40,43 +40,7 @@ module RST
|
|
40
40
|
#
|
41
41
|
module Calendar
|
42
42
|
|
43
|
-
|
44
|
-
module CalendarHelper
|
45
|
-
|
46
|
-
# You can use 'today' or any format which Date.parse can handle.
|
47
|
-
# @param [nil|String|Time|Date] param
|
48
|
-
# @return [Date] always returns a Date regardless of the type of input
|
49
|
-
def ensure_date(param)
|
50
|
-
if param.is_a?(Date) || param.is_a?(::Time)
|
51
|
-
param
|
52
|
-
elsif param =~ /today/i || param.nil?
|
53
|
-
Date.today
|
54
|
-
elsif param =~ /\d+[a-zA-Z]/i
|
55
|
-
get_today_plus(param)
|
56
|
-
else
|
57
|
-
Date.parse(param)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# Get Today + param
|
62
|
-
# @param [String] param nDWM n=Number Day Weeks Months
|
63
|
-
def get_today_plus(param)
|
64
|
-
offset = 0
|
65
|
-
param.scan(/(\d+)([a-z])/i) do |count,unit|
|
66
|
-
offset = case unit[0].downcase
|
67
|
-
when 'd'
|
68
|
-
count.to_i.days
|
69
|
-
when 'w'
|
70
|
-
count.to_i.weeks
|
71
|
-
when 'm'
|
72
|
-
count.to_i.months
|
73
|
-
else
|
74
|
-
raise "Unknown unit #{unit}. Valid units are d,w,m or days,weeks,months"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
Date.parse( (Time.now + offset).to_s )
|
78
|
-
end
|
79
|
-
end
|
43
|
+
include CalendarHelper
|
80
44
|
|
81
45
|
# Calendar has a name and will be stored in Persistent::DiskStore(CALENDAR_FILE)
|
82
46
|
# with it's name as the id. Thus you can save different calendars in
|
@@ -183,7 +147,7 @@ module RST
|
|
183
147
|
# @return [String]|nil
|
184
148
|
def to_text(from,to,empty=false,ids=false)
|
185
149
|
unless (_content=list_days(from,to)).empty?
|
186
|
-
left_column=build_cal(
|
150
|
+
left_column=build_cal(parse_date_param(from),parse_date_param(to))
|
187
151
|
right_column=("EVENTS:\n"+list_days(from,to,empty,ids).join("\n")).split(/\n/)
|
188
152
|
render_2col_lines(left_column, right_column)
|
189
153
|
end
|
@@ -264,13 +228,6 @@ module RST
|
|
264
228
|
|
265
229
|
# @endgroup
|
266
230
|
|
267
|
-
# Convert strings to a date
|
268
|
-
# @param [Date|Time|String] param - default is 'today'
|
269
|
-
# @return [Date|Time]
|
270
|
-
def parse_date_param(param=Date.today)
|
271
|
-
ensure_date(param)
|
272
|
-
end
|
273
|
-
|
274
231
|
end
|
275
232
|
|
276
233
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RST
|
2
|
+
|
3
|
+
# Some useful helpers for dates
|
4
|
+
module CalendarHelper
|
5
|
+
|
6
|
+
# You can use 'today' or any format which Date.parse can handle.
|
7
|
+
# @example
|
8
|
+
# parse_date_param('1w')
|
9
|
+
# parse_date_param('-41d')
|
10
|
+
# parse_date_param('1week')
|
11
|
+
# parse_date_param('4months')
|
12
|
+
# parse_date_param('-12m')
|
13
|
+
# parse_date_param('today')
|
14
|
+
# @param [nil|String|Time|Date] param
|
15
|
+
# @return [Date] always returns a Date regardless of the type of input
|
16
|
+
def parse_date_param(param)
|
17
|
+
if param.is_a?(Date) || param.is_a?(::Time)
|
18
|
+
param
|
19
|
+
elsif param =~ /today/i || param.nil?
|
20
|
+
Date.today
|
21
|
+
elsif param =~ /\d+[a-zA-Z]/i
|
22
|
+
get_today_plus(param)
|
23
|
+
else
|
24
|
+
Date.parse(param)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Get Today + param
|
31
|
+
# @example
|
32
|
+
# get_today_plus('1w')
|
33
|
+
# get_today_plus('-41d')
|
34
|
+
# get_today_plus('1week')
|
35
|
+
# get_today_plus('4months')
|
36
|
+
# get_today_plus('-12m')
|
37
|
+
# @param [String] param nDWM n=Number Day Weeks Months
|
38
|
+
def get_today_plus(param)
|
39
|
+
offset = 0
|
40
|
+
param.scan(/(\-?)(\d+)([a-z])/i) do |dir,count,unit|
|
41
|
+
_count = count.to_i * ( dir.to_s == '-' ? -1 : 1 )
|
42
|
+
offset = case unit[0].downcase
|
43
|
+
when 'd'
|
44
|
+
_count.to_i.days
|
45
|
+
when 'w'
|
46
|
+
_count.to_i.weeks
|
47
|
+
when 'm'
|
48
|
+
_count.to_i.months
|
49
|
+
else
|
50
|
+
raise "Unknown unit #{unit}. Valid units are d,w,m or days,weeks,months"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
Date.parse( (Time.now + offset).to_s )
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/rst.rb
CHANGED
@@ -45,6 +45,7 @@ module RST
|
|
45
45
|
# app = RstCommand.new(ARGV)
|
46
46
|
# app.run()
|
47
47
|
def initialize(args)
|
48
|
+
@options = {}
|
48
49
|
load_defaults
|
49
50
|
parse_options(args)
|
50
51
|
_command = args.shift
|
@@ -126,7 +127,7 @@ module RST
|
|
126
127
|
|
127
128
|
opts.separator ' Calendar-actions'
|
128
129
|
|
129
|
-
opts.on('-p', '--print-calendar', 'Print calendar') do |p|
|
130
|
+
opts.on('-p', '--[no-]print-calendar', 'Print calendar') do |p|
|
130
131
|
@options[:print_calendar] = p
|
131
132
|
end
|
132
133
|
|
@@ -158,7 +159,7 @@ module RST
|
|
158
159
|
@options[:save_defaults] = v
|
159
160
|
end
|
160
161
|
|
161
|
-
opts.on('--list-defaults', 'list saved defaults') do |v|
|
162
|
+
opts.on('--[no-]list-defaults', 'list saved defaults') do |v|
|
162
163
|
@options[:list_defaults] = v
|
163
164
|
end
|
164
165
|
|
@@ -253,9 +254,9 @@ module RST
|
|
253
254
|
def run_option(option)
|
254
255
|
case option.to_s
|
255
256
|
when 'examples'
|
256
|
-
File.read(File.join(DOCS,'examples.md')).strip
|
257
|
+
File.read(File.join(DOCS,'examples.md')).strip if options[:examples]
|
257
258
|
when 'verbose'
|
258
|
-
print_arguments
|
259
|
+
print_arguments if options[:verbose]
|
259
260
|
when 'new_event'
|
260
261
|
new_event = add_event
|
261
262
|
"Added: %s: %s" % [new_event.event_date.strftime(DEFAULT_DATE_FORMAT), new_event.event_headline.strip]
|
@@ -270,7 +271,7 @@ module RST
|
|
270
271
|
when 'save_defaults'
|
271
272
|
save_defaults
|
272
273
|
when 'list_defaults'
|
273
|
-
list_defaults
|
274
|
+
list_defaults if options[:list_defaults]
|
274
275
|
when 'clear_defaults'
|
275
276
|
clear_defaults
|
276
277
|
else
|
data/rst.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyshelltools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.10
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Andi Altendorfer
|
@@ -14,7 +13,6 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: redcarpet
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
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
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: yard
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -76,6 +69,7 @@ files:
|
|
76
69
|
- lib/load.rb
|
77
70
|
- lib/modules/calendar/calendar.rb
|
78
71
|
- lib/modules/calendar/calendar_event.rb
|
72
|
+
- lib/modules/calendar/calendar_helper.rb
|
79
73
|
- lib/modules/calendar/eventable.rb
|
80
74
|
- lib/modules/persistent/disk_store.rb
|
81
75
|
- lib/modules/persistent/memory_store.rb
|
@@ -87,27 +81,26 @@ files:
|
|
87
81
|
- assets/docs/examples.md
|
88
82
|
homepage: http://rubygems.org/gems/rubyshelltools
|
89
83
|
licenses: []
|
84
|
+
metadata: {}
|
90
85
|
post_install_message:
|
91
86
|
rdoc_options: []
|
92
87
|
require_paths:
|
93
88
|
- lib
|
94
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
90
|
requirements:
|
97
91
|
- - '>='
|
98
92
|
- !ruby/object:Gem::Version
|
99
93
|
version: '0'
|
100
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
95
|
requirements:
|
103
96
|
- - '>='
|
104
97
|
- !ruby/object:Gem::Version
|
105
98
|
version: '0'
|
106
99
|
requirements: []
|
107
100
|
rubyforge_project:
|
108
|
-
rubygems_version:
|
101
|
+
rubygems_version: 2.0.0
|
109
102
|
signing_key:
|
110
|
-
specification_version:
|
103
|
+
specification_version: 4
|
111
104
|
summary: Ruby Shell Tools
|
112
105
|
test_files: []
|
113
106
|
has_rdoc:
|