rubyshelltools 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -69,6 +69,19 @@ The latest version is online at my [DAV-server][] too.
69
69
  Browsing the code
70
70
  -----------------
71
71
 
72
+ **To get a glue what's goin on**
73
+
74
+ do a `rspec --format d specs/` in the project's root
75
+
76
+ Command-line arguments
77
+ --verbose - should list interpreted options and files with --verbose
78
+ ls - should list files with 'ls'
79
+ --help - should print help
80
+ --examples - should print out examples from doc/examples.md
81
+
82
+ ..... cut out a lot of lines .....
83
+
84
+
72
85
  **modules**
73
86
 
74
87
  Modules are the core of this project. Within the directory
@@ -7,39 +7,43 @@ rst --help
7
7
  Print out available options and commands
8
8
 
9
9
  $ rst --help
10
- Usage: rst [COMMAND] [options] [FILES..]
11
-
12
- Options:
13
- -v, --[no-]verbose Run verbosely
14
- --examples Show some usage examples
15
- -h, --help Print help
16
- -f, --from DATE Set from-date
17
- -t, --to DATE Set to-date
18
- -n, --name NAME Use this name for the command
19
- -e, --new-event [DATE,]STRING Add an event
20
- --list-calendars List available calendars
21
- --delete-calendar CALENDARNAME
22
- Delete an calendar and all it's entries!
23
- --[no-]empty Show empty entries
24
- --save-defaults Save given params as defaults
25
- --list-defaults list saved defaults
26
- --clear-defaults delete previously saved defaults
27
-
28
- Commands:
29
- nil .......... no command. Interpret options only (useful in combination with -v)
30
- ls ........... list directory and files
31
- cal[endar] ... print a calendar --from --to
32
-
33
- DATE-FORMATS FOR --new-event:
34
- omitted....... today
35
- today ........ today
36
- nDWM ......... today + n days, weeks, months eg 1w, 2d[ays], 1M[ONTH]
37
- yyyy-mm-dd
38
- dd.mm.yyyy
39
- mm/dd/yyyy
40
-
41
- use --example for a more detailed list of commands.
42
10
 
11
+ Usage: rst [COMMAND] [options] [FILES..]
12
+
13
+ Options:
14
+ -v, --[no-]verbose Run verbosely
15
+ --examples Show some usage examples
16
+ -h, --help Print help
17
+ -f, --from DATE Set from-date
18
+ -t, --to DATE Set to-date
19
+ -n, --name NAME Use this name for the command
20
+ -e, --new-event [DATE,]STRING Add an event
21
+ --list-calendars List available calendars
22
+ --delete-calendar CALENDARNAME
23
+ Delete an calendar and all it's entries!
24
+ --delete-events ID[,ID,...] delete entries from calendar
25
+ --[no-]empty Show empty entries
26
+ -i, --with-ids List entries with ids
27
+ -d, --dump Dump calendar-events
28
+ --save-defaults Save given params as defaults
29
+ --list-defaults list saved defaults
30
+ --clear-defaults delete previously saved defaults
31
+ -p, --print-calendar Print calendar
32
+
33
+ Commands:
34
+ nil .......... No command. Interpret options only (useful in combination with -v)
35
+ ls ........... List directory and files
36
+ cal[endar] ... Print a calendar --from --to
37
+
38
+ DATE-FORMATS FOR --new-event:
39
+ omitted....... Today
40
+ today ........ Today
41
+ nDWM ......... Today + n days, weeks, months eg 1w, 2d[ays], 1M[ONTH]
42
+ yyyy-mm-dd
43
+ dd.mm.yyyy
44
+ mm/dd/yyyy
45
+
46
+ Use --example for a more detailed list of commands.
43
47
  rst ls *
44
48
  --------
45
49
 
@@ -121,14 +125,14 @@ Print a pretty calendar
121
125
  $ rst cal -n work --print-calendar
122
126
 
123
127
  April 2013 EVENTS:
124
- Su Mo Tu We Th Fr Sa Wed, Apr 24 2013: RailsConf2013 7h Abflug München + TÜV-Audit
128
+ Su Mo Tu We Th Fr Sa Wed, Apr 24 2013: RailsConf2013 7h Departure Munich + TUV Audit
125
129
  1 2 3 4 5 6 Mon, Apr 29 2013: RailsConf2013
126
130
  7 8 9 10 11 12 13 Tue, Apr 30 2013: RailsConf2013
127
131
  14 15 16 17 18 19 20 Wed, May 01 2013: RailsConf2013
128
132
  21 22 23 24 25 26 27 Thu, May 02 2013: RailsConf2013
129
133
  28 29 30 Fri, May 03 2013: RailsConf2013
130
- Sat, May 04 2013: RailsConf2013 Ankunft München
131
- Mon, May 06 2013: Prüfung Romy
134
+ Sat, May 04 2013: RailsConf2013 Arrival Munich
135
+ Mon, May 06 2013: Exam Romy
132
136
  May 2013
133
137
  Su Mo Tu We Th Fr Sa
134
138
  1 2 3 4
@@ -89,13 +89,14 @@ module RST
89
89
  include Persistent::Persistentable
90
90
  include CalendarHelper
91
91
 
92
- # @group public api
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
99
+ # @param [Array] _events initial events
99
100
  # @see DEFAULT_CALENDAR_NAME
100
101
  def initialize(_name=DEFAULT_CALENDAR_NAME, _start=nil, _end=nil, _events=[])
101
102
  @name = _name
@@ -177,34 +178,65 @@ module RST
177
178
  # events within given date-range
178
179
  # @param [String|Date] from - Start on date
179
180
  # @param [String|Date] to - End on date
180
- # @return [String]
181
+ # @param [Boolean] empty - show empty lines (dates without events)
182
+ # @param [Boolean] ids - show ids of each event
183
+ # @return [String]|nil
181
184
  def to_text(from,to,empty=false,ids=false)
182
185
  unless (_content=list_days(from,to)).empty?
183
186
  left_column=build_cal(ensure_date(from),ensure_date(to))
184
187
  right_column=("EVENTS:\n"+list_days(from,to,empty,ids).join("\n")).split(/\n/)
185
- rows = []
186
- source = left_column.count > right_column.count ? left_column : right_column
187
- source.each_with_index do |_r,idx|
188
- rows << "%-22.22s %s " % [ left_column[idx].to_s+" ", right_column[idx].to_s ]
189
- end
190
- rows.join("\n").gsub(/\s*$/,'')
188
+ render_2col_lines(left_column, right_column)
191
189
  end
192
190
  end
193
191
  # @endgroup
194
192
 
195
193
  private
196
- # @group private api
194
+ # @group private API
197
195
 
196
+ # Format a 2 column text-output
197
+ # @example
198
+ #
199
+ # $ bin/rst -p
200
+ # work
201
+ # April 2013 EVENTS:
202
+ # Su Mo Tu We Th Fr Sa Wed, Apr 24 2013: RailsConf2013 7h Abflug München + TÜV-Audit
203
+ # 1 2 3 4 5 6 Mon, Apr 29 2013: RailsConf2013
204
+ # 7 8 9 10 11 12 13 Tue, Apr 30 2013: RailsConf2013
205
+ # 14 15 16 17 18 19 20 Wed, May 01 2013: RailsConf2013
206
+ # 21 22 23 24 25 26 27 Thu, May 02 2013: RailsConf2013
207
+ # 28 29 30 Fri, May 03 2013: RailsConf2013
208
+ # Sat, May 04 2013: RailsConf2013 Ankunft München
209
+ # Mon, May 06 2013: Exam Romy
210
+ # May 2013
211
+ # Su Mo Tu We Th Fr Sa
212
+ # 1 2 3 4
213
+ # 5 6 7 8 9 10 11
214
+ # 12 13 14 15 16 17 18
215
+ # 19 20 21 22 23 24 25
216
+ # 26 27 28 29 30 31V
217
+ #
218
+ # @param [Array] left - lines for the left column
219
+ # @param [Array] right - lines for the right column
220
+ # @return [String] - 2 column text-lines
221
+ def render_2col_lines(left,right)
222
+ source = left.count > right.count ? left : right
223
+ rows = []
224
+ source.each_with_index do |_r,idx|
225
+ rows << "%-22.22s %s " % [ left[idx].to_s+" ", right[idx].to_s ]
226
+ end
227
+ rows.join("\n").gsub(/\s*$/,'')
228
+ end
198
229
 
199
- # Uses OS'cal-command to format a small calendar for a given month
230
+ # Uses OS' cal-command to format a small calendar for a given month
200
231
  # @param [Date|String] from - start on date
201
232
  # @param [Date|String] to - end on date
202
- # @return [Arra] of text-lines
233
+ # @return [Array] of text-lines
203
234
  def build_cal from, to
204
235
  (from..to).map{ |d| [d.month, d.year ] }.uniq.map { |m,y|
205
236
  `cal #{m} #{y}`
206
237
  }.join("\n").split(/\n/)
207
238
  end
239
+
208
240
  # Output date and Events on this date in one line
209
241
  # @param [Date] _date
210
242
  # @param [Boolean] show_empty - do output lines with no events
@@ -3,7 +3,7 @@ module RST
3
3
  module Calendar
4
4
 
5
5
  # A CalendarEvent happens on a given date and has a label.
6
- # It's can be used in a Calendar
6
+ # It can be used in a Calendar
7
7
  # @see Calendar::Calendar
8
8
  # @see Calendar::Eventable
9
9
  # @example
@@ -60,11 +60,10 @@ module RST
60
60
  def move_store store
61
61
  if @store && @store != store
62
62
  raise NotImplementedError.new('An object can\'t be moved to another store')
63
- elsif @store == store
64
- self
65
- else
63
+ elsif @store != store
66
64
  @store = store
67
65
  end
66
+ self.store
68
67
  end
69
68
  end
70
69
 
@@ -43,11 +43,18 @@ module RST
43
43
  end
44
44
 
45
45
  # @param [Array|String] ids or id to search
46
+ # @yield [Object] for each object found
46
47
  # @return [nil] if nothing found
47
48
  # @return [Object] if exactly one object found
48
49
  # @return [Array] of objects with matching ids if more than one matched
49
50
  def find(*ids)
50
- flatten all.select { |obj| ids.include?(obj.id) }
51
+ if block_given?
52
+ all.select { |obj| ids.include?(obj.id) }.each do |obj|
53
+ yield(obj)
54
+ end
55
+ else
56
+ flatten all.select { |obj| ids.include?(obj.id) }
57
+ end
51
58
  end
52
59
 
53
60
 
data/lib/rst.rb CHANGED
@@ -41,6 +41,9 @@ module RST
41
41
  attr_reader :command
42
42
 
43
43
  # Initialize the Command-runner with arguments and parse them.
44
+ # @example
45
+ # app = RstCommand.new(ARGV)
46
+ # app.run()
44
47
  def initialize(args)
45
48
  load_defaults
46
49
  parse_options(args)
@@ -70,20 +73,32 @@ module RST
70
73
  OptionParser.new do |opts|
71
74
  opts.banner = 'Usage: rst [COMMAND] [options] [FILES..]'
72
75
 
76
+ opts.separator "\nCommands:"
77
+ opts.separator <<-EOT
78
+ nil .......... no command. Interpret options only (useful in combination with -v)
79
+ ls ........... list directory and files
80
+ cal[endar] ... print a calendar. See Calendar-options.
81
+ EOT
82
+ .gsub(/^\s+/,' ')
83
+
73
84
  opts.separator "\nOptions:"
74
85
 
75
86
  opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
76
87
  @options[:verbose] = v
77
88
  end
78
89
 
79
- opts.on('--examples', 'Show some usage examples') do |x|
90
+ opts.on('--examples', 'Show usage examples') do |x|
80
91
  @options[:examples] = x
81
92
  end
82
93
 
83
- opts.on('-h', '--help', 'Print help') do |h|
94
+ opts.on('-h', '--help', 'Print (this) help') do |h|
84
95
  puts opts
85
96
  end
86
97
 
98
+ opts.separator ''
99
+ opts.separator 'Calendar-options:'
100
+
101
+ opts.separator ' Calendar-metadata'
87
102
  opts.on('-f', '--from DATE', String, 'Set from-date') do |from|
88
103
  @options[:from] = from
89
104
  end
@@ -92,11 +107,12 @@ module RST
92
107
  @options[:to] = to
93
108
  end
94
109
 
95
- opts.on('-n', '--name NAME', String, 'Use this name for the command') do |name|
110
+ opts.on('-n', '--name NAME', String, 'Use this name for eg. calendar') do |name|
96
111
  @options[:name] = name
97
112
  end
98
113
 
99
- opts.on('-e', '--new-event [DATE,]STRING', Array, 'Add an event') do |date,name|
114
+ opts.separator ' Events'
115
+ opts.on('-e', '--new-event [DATE,]STRING', Array, 'Add an event to NAME') do |date,name|
100
116
  if name.nil?
101
117
  name = date
102
118
  date = Date.today
@@ -104,18 +120,30 @@ module RST
104
120
  @options[:new_event] = {date: date, label: name}
105
121
  end
106
122
 
123
+ opts.on('--delete-events ID[,ID,...]',Array, 'delete entries from calendar NAME') do |ids|
124
+ @options[:delete_events] = ids
125
+ end
126
+
127
+ opts.separator ' Calendar-actions'
128
+
129
+ opts.on('-p', '--print-calendar', 'Print calendar') do |p|
130
+ @options[:print_calendar] = p
131
+ end
132
+
133
+ opts.on('-d', '--dump', 'Dump calendar-events' ) do |d|
134
+ @options[:dump] = d
135
+ end
136
+
107
137
  opts.on('--list-calendars', 'List available calendars') do
108
138
  @options[:list_calendars] = true
109
139
  end
110
140
 
111
- opts.on('--delete-calendar CALENDARNAME', String, 'Delete an calendar and all it\'s entries!') do |name|
141
+ opts.on('--delete-calendar CALNAME', String, 'Delete an calendar and all it\'s entries!') do |name|
112
142
  @options[:delete_calendar] = name
113
143
  end
114
144
 
115
- opts.on('--delete-events ID[,ID,...]',Array, 'delete entries from calendar') do |ids|
116
- @options[:delete_events] = ids
117
- end
118
145
 
146
+ opts.separator ' Output-options'
119
147
  opts.on('--[no-]empty', 'Show empty entries') do |show|
120
148
  @options[:show_empty] = show
121
149
  end
@@ -124,10 +152,8 @@ module RST
124
152
  @options[:with_ids] = ids
125
153
  end
126
154
 
127
- opts.on('-d', '--dump', 'Dump calendar-events' ) do |d|
128
- @options[:dump] = d
129
- end
130
-
155
+ opts.separator ''
156
+ opts.separator 'Other options:'
131
157
  opts.on('--save-defaults', 'Save given params as defaults') do |v|
132
158
  @options[:save_defaults] = v
133
159
  end
@@ -140,22 +166,8 @@ module RST
140
166
  @options[:clear_defaults] = v
141
167
  end
142
168
 
143
- opts.on('-p', '--print-calendar', 'Print calendar') do |p|
144
- @options[:print_calendar] = p
145
- end
146
-
147
- opts.separator ''
148
- opts.separator 'Commands:'
149
-
150
- opts.separator <<-EOT
151
- nil .......... no command. Interpret options only (useful in combination with -v)
152
- ls ........... list directory and files
153
- cal[endar] ... print a calendar --from --to
154
- EOT
155
- .gsub(/^\s+/,' ')
156
-
157
169
  opts.separator ''
158
- opts.separator 'DATE-FORMATS FOR --new-event:'
170
+ opts.separator 'DATE-formats used in --to, --form, and --new-event:'
159
171
  opts.separator <<-EOT
160
172
  omitted....... today
161
173
  today ........ today
@@ -375,8 +387,7 @@ module RST
375
387
  def save_defaults
376
388
  store = Persistent::DiskStore.new('defaults')
377
389
  options.delete(:save_defaults)
378
- defaults = Defaults.new( command, options )
379
- store << defaults
390
+ store << Defaults.new( command, options )
380
391
  "Defaults saved"
381
392
  end
382
393
 
data/rst.rb CHANGED
@@ -3,7 +3,7 @@ require 'logger'
3
3
  # # Ruby Shell Tools Top-level file
4
4
  module RST
5
5
  # Gem-version
6
- VERSION = '0.0.8'
6
+ VERSION = '0.0.9'
7
7
 
8
8
  # Path to the docs used by the software
9
9
  DOCS = File.expand_path('../assets/docs', __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyshelltools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: