rubyshelltools 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/assets/docs/examples.md +9 -0
- data/lib/modules/calendar/calendar.rb +39 -9
- data/lib/rst.rb +19 -2
- data/rst.rb +1 -1
- metadata +1 -1
data/assets/docs/examples.md
CHANGED
@@ -106,6 +106,15 @@ The full set of parameters is
|
|
106
106
|
* --empty ...... show empty lines
|
107
107
|
* --no-empty ... show no empty lines (default)
|
108
108
|
|
109
|
+
List entries with IDs and delete by ID
|
110
|
+
--------------------------------------
|
111
|
+
|
112
|
+
$ rst cal -i
|
113
|
+
Sun, Mar 31 2013:
|
114
|
+
e5e14e59 > Your Event ...
|
115
|
+
|
116
|
+
$ rst cal --delete-event e5e14e59
|
117
|
+
|
109
118
|
|
110
119
|
Save defaults
|
111
120
|
=============
|
@@ -39,7 +39,7 @@ module RST
|
|
39
39
|
# # => Thu, May 22 1997: Tina's Birthday
|
40
40
|
#
|
41
41
|
module Calendar
|
42
|
-
|
42
|
+
|
43
43
|
# Some helper-methods useful when dealing with dates
|
44
44
|
module CalendarHelper
|
45
45
|
|
@@ -92,7 +92,7 @@ module RST
|
|
92
92
|
# @group public api
|
93
93
|
|
94
94
|
attr_reader :name, :start_date, :end_date, :events
|
95
|
-
|
95
|
+
|
96
96
|
# @param [String] _name Name and persistent-id of this calendar.
|
97
97
|
# @param [Date|Time|String] _start The date when the calendar starts
|
98
98
|
# @param [Date|Time|String] _end The date when the calendar ends
|
@@ -129,13 +129,13 @@ module RST
|
|
129
129
|
def <<(add)
|
130
130
|
events << add
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
# Calculate the span between start and end in seconds
|
134
134
|
# @return [Float]
|
135
135
|
def span
|
136
136
|
((end_date - start_date)*Numeric::DAYS).to_f
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
# Array of strings for each day with events on it.
|
140
140
|
#
|
141
141
|
# @example
|
@@ -150,8 +150,8 @@ module RST
|
|
150
150
|
format_events_for(_date,show_empty,show_ids)
|
151
151
|
}.compact
|
152
152
|
end
|
153
|
-
|
154
|
-
|
153
|
+
|
154
|
+
|
155
155
|
# All events on the given date
|
156
156
|
# @param [Date] date
|
157
157
|
# @return [Array] of [CalendarEvents]
|
@@ -162,17 +162,47 @@ module RST
|
|
162
162
|
|
163
163
|
# Dump calendar events
|
164
164
|
# @return [String]
|
165
|
-
def dump
|
165
|
+
def dump show_ids=false
|
166
166
|
events.map { |event|
|
167
|
-
|
167
|
+
if show_ids
|
168
|
+
'%-8.8s %-15.15s "%s,%s"' % [ event.id, self.name, event.event_date.strftime('%Y-%m-%d'), event.event_headline ]
|
169
|
+
else
|
170
|
+
'"%s,%s"' % [ event.event_date.strftime('%Y-%m-%d'), event.event_headline ]
|
171
|
+
end
|
168
172
|
}.join("\n")
|
169
173
|
end
|
170
174
|
|
175
|
+
# Output a calendar for the given range.Including a small
|
176
|
+
# monthly calendar on the upper, left and a list of all
|
177
|
+
# events within given date-range
|
178
|
+
def to_text(from,to)
|
179
|
+
unless (_content=list_days(from,to)).empty?
|
180
|
+
_date = ensure_date(from)
|
181
|
+
left_column=build_cal(_date,ensure_date(to))
|
182
|
+
right_column=["EVENTS:"] + list_days(from,to)
|
183
|
+
rows = []
|
184
|
+
source = left_column.count > right_column.count ? left_column : right_column
|
185
|
+
source.each_with_index do |_r,idx|
|
186
|
+
rows << "%-22.22s %s " % [ left_column[idx].to_s+" ", right_column[idx].to_s ]
|
187
|
+
end
|
188
|
+
rows.join("\n").gsub(/\s*$/,'')
|
189
|
+
end
|
190
|
+
end
|
171
191
|
# @endgroup
|
172
192
|
|
173
193
|
private
|
174
194
|
# @group private api
|
175
195
|
|
196
|
+
|
197
|
+
# Uses OS'cal-command to format a small calendar for a given month
|
198
|
+
# @param [Date|String] from - start on date
|
199
|
+
# @param [Date|String] to - end on date
|
200
|
+
# @return [Arra] of text-lines
|
201
|
+
def build_cal from, to
|
202
|
+
(from..to).map{ |d| [d.month, d.year ] }.uniq.map { |m,y|
|
203
|
+
`cal #{m} #{y}`
|
204
|
+
}.join("\n\n").split(/\n/)
|
205
|
+
end
|
176
206
|
# Output date and Events on this date in one line
|
177
207
|
# @param [Date] _date
|
178
208
|
# @param [Boolean] show_empty - do output lines with no events
|
@@ -197,7 +227,7 @@ module RST
|
|
197
227
|
}.join("\n ").strip
|
198
228
|
end
|
199
229
|
end
|
200
|
-
|
230
|
+
|
201
231
|
# @endgroup
|
202
232
|
|
203
233
|
# Convert strings to a date
|
data/lib/rst.rb
CHANGED
@@ -140,6 +140,10 @@ module RST
|
|
140
140
|
@options[:clear_defaults] = v
|
141
141
|
end
|
142
142
|
|
143
|
+
opts.on('-p', '--print-calendar', 'Print calendar') do |p|
|
144
|
+
@options[:print_calendar] = p
|
145
|
+
end
|
146
|
+
|
143
147
|
opts.separator ''
|
144
148
|
opts.separator 'Commands:'
|
145
149
|
|
@@ -192,7 +196,12 @@ module RST
|
|
192
196
|
@files << '*' if @files.empty?
|
193
197
|
directory_listing( @files )
|
194
198
|
when 'cal', 'calendar'
|
195
|
-
print_calendar
|
199
|
+
if @options[:print_calendar]
|
200
|
+
print_long_calendar
|
201
|
+
else
|
202
|
+
print_calendar
|
203
|
+
end
|
204
|
+
|
196
205
|
else
|
197
206
|
"unknown command '#{cmd.inspect}' - try --help"
|
198
207
|
end
|
@@ -288,6 +297,14 @@ module RST
|
|
288
297
|
}
|
289
298
|
end
|
290
299
|
|
300
|
+
# Print a nice calendar with all events
|
301
|
+
def print_long_calendar
|
302
|
+
store = Persistent::DiskStore.new(CALENDAR_FILE)
|
303
|
+
store.all.map { |calendar|
|
304
|
+
calendar.to_text(@options[:from], @options[:to])
|
305
|
+
}.join("\n\n")
|
306
|
+
end
|
307
|
+
|
291
308
|
# Dump the calendar(s), thus the output can be used as input for -e again
|
292
309
|
# if no name-param is given all calendars are dumped.
|
293
310
|
# if name-param is given only the named calendar gets dumped.
|
@@ -295,7 +312,7 @@ module RST
|
|
295
312
|
def dump_calendar
|
296
313
|
store = Persistent::DiskStore.new(CALENDAR_FILE)
|
297
314
|
store.all.map { |calendar|
|
298
|
-
calendar.dump if calendar.name == @options[:name] || @options[:name].blank?
|
315
|
+
calendar.dump(@options[:with_ids]) if calendar.name == @options[:name] || @options[:name].blank?
|
299
316
|
}.compact.join("\n")
|
300
317
|
end
|
301
318
|
|
data/rst.rb
CHANGED