labrat 1.2.1 → 1.2.3

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.
@@ -116,8 +116,8 @@ module Labrat
116
116
  meas = match[:measure].to_f
117
117
  u_meth = match[:unit].to_sym
118
118
  unless meas.respond_to?(u_meth)
119
- msg = "Error: unknown #{where} unit: '#{match[:unit]}'\n"\
120
- " valid units are: pt, mm, cm, dm, m, in, ft, yd"
119
+ msg = "Error: unknown #{where} unit: '#{match[:unit]}'\n " \
120
+ "valid units are: pt, mm, cm, dm, m, in, ft, yd"
121
121
  raise Labrat::DimensionError, msg
122
122
  end
123
123
  points = meas.send(u_meth)
@@ -130,31 +130,49 @@ module Labrat
130
130
  # printed on.
131
131
  def page_dimension_options
132
132
  # Specifies an optional option argument
133
- parser.on("-wDIM", "--page-width=DIM",
134
- "Horizontal dimension of a page of labels as it comes out of the printer") do |wd|
133
+ parser.on(
134
+ "-wDIM",
135
+ "--page-width=DIM",
136
+ "Horizontal dimension of a page of labels as it comes out of the printer",
137
+ ) do |wd|
135
138
  options.page_width = parse_dimension(wd, 'page-width')
136
139
  end
137
- parser.on("-hDIM", "--page-height=DIM",
138
- "Vertical dimension of a page of labels as it comes out of the printer") do |ht|
140
+ parser.on(
141
+ "-hDIM",
142
+ "--page-height=DIM",
143
+ "Vertical dimension of a page of labels as it comes out of the printer",
144
+ ) do |ht|
139
145
  options.page_height = parse_dimension(ht, 'page-height')
140
146
  end
141
- parser.on("-RNUM", "--rows=NUM", Integer,
142
- "Number of rows of labels on a page") do |n|
147
+ parser.on(
148
+ "-RNUM",
149
+ "--rows=NUM",
150
+ Integer,
151
+ "Number of rows of labels on a page",
152
+ ) do |n|
143
153
  options.rows = n
144
154
  warn " ::rows <- #{n}::" if options.verbose
145
155
  end
146
- parser.on("-CNUM", "--columns=NUM", Integer,
147
- "Number of columns of labels on a page") do |n|
156
+ parser.on(
157
+ "-CNUM",
158
+ "--columns=NUM",
159
+ Integer,
160
+ "Number of columns of labels on a page",
161
+ ) do |n|
148
162
  options.columns = n
149
163
  warn " ::columns <- #{n}::" if options.verbose
150
164
  end
151
- parser.on("--row-gap=DIM",
152
- "Vertical space between rows of labels on a page") do |gap|
165
+ parser.on(
166
+ "--row-gap=DIM",
167
+ "Vertical space between rows of labels on a page",
168
+ ) do |gap|
153
169
  options.row_gap = parse_dimension(gap, 'row-gap')
154
170
  end
155
- parser.on("--column-gap=DIM",
156
- "Column gap:",
157
- "Horizontal space between columns of labels on a page") do |gap|
171
+ parser.on(
172
+ "--column-gap=DIM",
173
+ "Column gap:",
174
+ "Horizontal space between columns of labels on a page",
175
+ ) do |gap|
158
176
  options.column_gap = parse_dimension(gap, 'column-gap')
159
177
  end
160
178
  end
@@ -163,32 +181,46 @@ module Labrat
163
181
  # top, and bottom are named assuming a portrait orientation, that is the
164
182
  # orientation of the page as it comes out of the printer.
165
183
  def page_margin_options
166
- parser.on("--right-page-margin=DIM",
167
- "Distance from right side of page (in portrait) to print area") do |x|
184
+ parser.on(
185
+ "--right-page-margin=DIM",
186
+ "Distance from right side of page (in portrait) to print area",
187
+ ) do |x|
168
188
  options.right_page_margin = parse_dimension(x, 'right-page-margin')
169
189
  end
170
- parser.on("--left-page-margin=DIM",
171
- "Distance from left side of page (in portrait) to print area") do |x|
190
+ parser.on(
191
+ "--left-page-margin=DIM",
192
+ "Distance from left side of page (in portrait) to print area",
193
+ ) do |x|
172
194
  options.left_page_margin = parse_dimension(x, 'left-page-margin')
173
195
  end
174
- parser.on("--top-page-margin=DIM",
175
- "Distance from top side of page (in portrait) to print area") do |x|
196
+ parser.on(
197
+ "--top-page-margin=DIM",
198
+ "Distance from top side of page (in portrait) to print area",
199
+ ) do |x|
176
200
  options.top_page_margin = parse_dimension(x, 'top-page-margin')
177
201
  end
178
- parser.on("--bottom-page-margin=DIM",
179
- "Distance from bottom side of page (in portrait) to print area") do |x|
202
+ parser.on(
203
+ "--bottom-page-margin=DIM",
204
+ "Distance from bottom side of page (in portrait) to print area",
205
+ ) do |x|
180
206
  options.bottom_page_margin = parse_dimension(x, 'bottom-page-margin')
181
207
  end
182
- parser.on("--h-page-margin=DIM",
183
- "Distance from left and right sides of page (in portrait) to print area") do |x|
208
+ parser.on(
209
+ "--h-page-margin=DIM",
210
+ "Distance from left and right sides of page (in portrait) to print area",
211
+ ) do |x|
184
212
  options.left_page_margin = options.right_page_margin = parse_dimension(x, 'h-page-margin')
185
213
  end
186
- parser.on("--v-page-margin=DIM",
187
- "Distance from top and bottom sides of page (in portrait) to print area") do |x|
214
+ parser.on(
215
+ "--v-page-margin=DIM",
216
+ "Distance from top and bottom sides of page (in portrait) to print area",
217
+ ) do |x|
188
218
  options.top_page_margin = options.bottom_page_margin = parse_dimension(x, 'v-page-margin')
189
219
  end
190
- parser.on("--page-margin=DIM",
191
- "Distance from all sides of page (in portrait) to print area") do |x|
220
+ parser.on(
221
+ "--page-margin=DIM",
222
+ "Distance from all sides of page (in portrait) to print area",
223
+ ) do |x|
192
224
  options.left_page_margin = options.right_page_margin =
193
225
  options.top_page_margin = options.bottom_page_margin = parse_dimension(x, 'margin')
194
226
  end
@@ -199,8 +231,11 @@ module Labrat
199
231
  # need not be specified.
200
232
  def label_name_option
201
233
  # options.raw_label = nil
202
- parser.on("-lNAME", "--label=NAME",
203
- "Use options for label type NAME from label database") do |name|
234
+ parser.on(
235
+ "-lNAME",
236
+ "--label=NAME",
237
+ "Use options for label type NAME from label database",
238
+ ) do |name|
204
239
  options.raw_label ||= name
205
240
  if labels_seen.include?(name)
206
241
  msg = "label option '#{name}' has circular reference"
@@ -226,8 +261,10 @@ module Labrat
226
261
  end
227
262
 
228
263
  def list_labels_option
229
- parser.on("--list-labels",
230
- "List known label types from label database and exit") do
264
+ parser.on(
265
+ "--list-labels",
266
+ "List known label types from label database and exit",
267
+ ) do
231
268
  db_paths = Labrat::LabelDb.db_paths
232
269
  lab_names = Labrat::LabelDb.known_names
233
270
  if db_paths.empty?
@@ -241,13 +278,13 @@ module Labrat
241
278
  max_width = lab_names.max_by(&:length).length
242
279
  ngrps = (78 / (max_width + 1)).floor
243
280
 
244
- lab_names.sort_by do |nm|
245
- nm.match(/\A([a-zA-z]+)([0-9]+)?/)
281
+ lab_names.sort_by { |nm|
282
+ nm =~ /\A([a-zA-Z]+)([0-9]+)?/
246
283
  [$1, $2.to_i || 0]
247
- end
284
+ }
248
285
  .groups_of(ngrps).each do |_n, grp|
249
- fmt = "%-#{max_width+1}s"
250
- grp = grp.map{|nm| sprintf(fmt, nm) }
286
+ fmt = "%-#{max_width + 1}s"
287
+ grp = grp.map { |nm| sprintf(fmt, nm) }
251
288
  warn " #{grp.join(' ')}"
252
289
  end
253
290
  end
@@ -257,13 +294,19 @@ module Labrat
257
294
 
258
295
  # Set the name, size, and style of font.
259
296
  def align_options
260
- parser.on("--h-align=[left|center|right|justify]", [:left, :center, :right, :justify],
261
- "Horizontal alignment of label text (default center)") do |al|
297
+ parser.on(
298
+ "--h-align=[left|center|right|justify]",
299
+ [:left, :center, :right, :justify],
300
+ "Horizontal alignment of label text (default center)",
301
+ ) do |al|
262
302
  options.h_align = al.to_sym
263
303
  warn " ::h-align <- #{al}::" if options.verbose
264
304
  end
265
- parser.on("--v-align=[top|center|bottom]", [:top, :center, :bottom],
266
- "Vertical alignment of label text (default center)") do |al|
305
+ parser.on(
306
+ "--v-align=[top|center|bottom]",
307
+ [:top, :center, :bottom],
308
+ "Vertical alignment of label text (default center)",
309
+ ) do |al|
267
310
  options.v_align = al.to_sym
268
311
  warn " ::v-align <- #{al}::" if options.verbose
269
312
  end
@@ -274,32 +317,46 @@ module Labrat
274
317
  # assuming a portrait orientation, that is the orientation the label has
275
318
  # as it comes out of the printer.
276
319
  def padding_options
277
- parser.on("--right-pad=DIM",
278
- "Distance from right side of label (in portrait) to print area") do |x|
320
+ parser.on(
321
+ "--right-pad=DIM",
322
+ "Distance from right side of label (in portrait) to print area",
323
+ ) do |x|
279
324
  options.right_pad = parse_dimension(x, 'right-pad')
280
325
  end
281
- parser.on("--left-pad=DIM",
282
- "Distance from left side of label (in portrait) to print area") do |x|
326
+ parser.on(
327
+ "--left-pad=DIM",
328
+ "Distance from left side of label (in portrait) to print area",
329
+ ) do |x|
283
330
  options.left_pad = parse_dimension(x, 'left-pad')
284
331
  end
285
- parser.on("--top-pad=DIM",
286
- "Distance from top side of label (in portrait) to print area") do |x|
332
+ parser.on(
333
+ "--top-pad=DIM",
334
+ "Distance from top side of label (in portrait) to print area",
335
+ ) do |x|
287
336
  options.top_pad = parse_dimension(x, 'top-pad')
288
337
  end
289
- parser.on("--bottom-pad=DIM",
290
- "Distance from bottom side of label (in portrait) to print area") do |x|
338
+ parser.on(
339
+ "--bottom-pad=DIM",
340
+ "Distance from bottom side of label (in portrait) to print area",
341
+ ) do |x|
291
342
  options.bottom_pad = parse_dimension(x, 'bottom-pad')
292
343
  end
293
- parser.on("--h-pad=DIM",
294
- "Distance from left and right sides of label (in portrait) to print area") do |x|
344
+ parser.on(
345
+ "--h-pad=DIM",
346
+ "Distance from left and right sides of label (in portrait) to print area",
347
+ ) do |x|
295
348
  options.left_pad = options.right_pad = parse_dimension(x, 'h-pad')
296
349
  end
297
- parser.on("--v-pad=DIM",
298
- "Distance from top and bottom sides of label (in portrait) to print area") do |x|
350
+ parser.on(
351
+ "--v-pad=DIM",
352
+ "Distance from top and bottom sides of label (in portrait) to print area",
353
+ ) do |x|
299
354
  options.top_pad = options.bottom_pad = parse_dimension(x, 'v-pad')
300
355
  end
301
- parser.on("--pad=DIM",
302
- "Distance from all sides of label (in portrait) to print area") do |x|
356
+ parser.on(
357
+ "--pad=DIM",
358
+ "Distance from all sides of label (in portrait) to print area",
359
+ ) do |x|
303
360
  options.left_pad = options.right_pad =
304
361
  options.top_pad = options.bottom_pad = parse_dimension(x, 'pad')
305
362
  end
@@ -307,19 +364,25 @@ module Labrat
307
364
 
308
365
  # Set the name, size, and style of font.
309
366
  def font_options
310
- parser.on("--font-name=NAME",
311
- "Name of font to use (default Helvetica)") do |nm|
367
+ parser.on(
368
+ "--font-name=NAME",
369
+ "Name of font to use (default Helvetica)",
370
+ ) do |nm|
312
371
  options.font_name = nm
313
372
  warn " ::font-name <- '#{nm}'::" if options.verbose
314
373
  end
315
- parser.on("--font-size=NUM",
316
- "Size of font to use in points (default 12)") do |pt|
374
+ parser.on(
375
+ "--font-size=NUM",
376
+ "Size of font to use in points (default 12)",
377
+ ) do |pt|
317
378
  options.font_size = pt
318
379
  warn " ::font-size <- #{pt}::" if options.verbose
319
380
  end
320
- parser.on("--font-style=[normal|bold|italic|bold-italic]",
321
- %w[normal bold italic bold-italic],
322
- "Style of font to use for text (default normal)") do |sty|
381
+ parser.on(
382
+ "--font-style=[normal|bold|italic|bold-italic]",
383
+ %w[normal bold italic bold-italic],
384
+ "Style of font to use for text (default normal)",
385
+ ) do |sty|
323
386
  # Prawn requires :bold_italic, not :"bold-italic"
324
387
  options.font_style = sty.tr('-', '_').to_sym
325
388
  warn " ::font-style <- #{sty}::" if options.verbose
@@ -331,29 +394,42 @@ module Labrat
331
394
  # sitting precisely where the user intends on the printed label. These
332
395
  # options tweak the PDF settings to compensate for any such anomalies.
333
396
  def delta_options
334
- parser.on('-xDIM', "--delta-x=DIM",
335
- "Left-right adjustment as label text is oriented") do |x|
397
+ parser.on(
398
+ '-xDIM',
399
+ "--delta-x=DIM",
400
+ "Left-right adjustment as label text is oriented",
401
+ ) do |x|
336
402
  options.delta_x = parse_dimension(x, 'delta-x')
337
403
  end
338
- parser.on('-yDIM', "--delta-y=DIM",
339
- "Up-down adjustment as label text is oriented") do |y|
404
+ parser.on(
405
+ '-yDIM',
406
+ "--delta-y=DIM",
407
+ "Up-down adjustment as label text is oriented",
408
+ ) do |y|
340
409
  options.delta_y = parse_dimension(y, 'delta-y')
341
410
  end
342
411
  end
343
412
 
344
413
  # The name of the printer to send the job to.
345
414
  def printer_name_option
346
- parser.on("-pNAME", "--printer=NAME",
347
- "Name of the label printer to print on") do |name|
415
+ parser.on(
416
+ "-pNAME",
417
+ "--printer=NAME",
418
+ "Name of the label printer to print on",
419
+ ) do |name|
348
420
  options.printer = name
349
421
  warn " ::printer <- '#{name}'::" if options.verbose
350
422
  end
351
423
  end
352
424
 
353
425
  def start_label_option
354
- parser.on("-SNUM", "--start-label=NUM", Integer,
355
- "Start printing at label number NUM (starting at 1, left-to-right, top-to-bottom)",
356
- " within first page only. Later pages always start at label 1.") do |n|
426
+ parser.on(
427
+ "-SNUM",
428
+ "--start-label=NUM",
429
+ Integer,
430
+ "Start printing at label number NUM (starting at 1, left-to-right, top-to-bottom)",
431
+ " within first page only. Later pages always start at label 1.",
432
+ ) do |n|
357
433
  options.start_label = n
358
434
  warn " ::start-label <- #{n}::" if options.verbose
359
435
  end
@@ -364,8 +440,11 @@ module Labrat
364
440
  # account. This allows the user to use some distinctive marker ('~~' by
365
441
  # default) to designate where a line break should occur.
366
442
  def nl_sep_option
367
- parser.on("-nSEP", "--nl-sep=SEPARATOR",
368
- "Specify text to be translated into a line-break (default '~~')") do |nl|
443
+ parser.on(
444
+ "-nSEP",
445
+ "--nl-sep=SEPARATOR",
446
+ "Specify text to be translated into a line-break (default '~~')",
447
+ ) do |nl|
369
448
  options.nl_sep = nl
370
449
  warn " ::nl-sep <- '#{nl}'::" if options.verbose
371
450
  end
@@ -375,16 +454,22 @@ module Labrat
375
454
  # allows the user to use some distinctive marker ('][' by default) to
376
455
  # designate where a new label shoul be started.
377
456
  def label_sep_option
378
- parser.on("--label-sep=SEPARATOR",
379
- "Specify text that indicates the start of a new label (default '==>')") do |ls|
380
- options.label-sep = ls
457
+ parser.on(
458
+ "--label-sep=SEPARATOR",
459
+ "Specify text that indicates the start of a new label (default '==>')",
460
+ ) do |ls|
461
+ options.label
381
462
  warn " ::label-sep <- '#{ls}'::" if options.verbose
382
463
  end
383
464
  end
384
465
 
385
466
  def copies_option
386
- parser.on("-cNUM", "--copies=NUM", Integer,
387
- "Number of copies of each label to generate") do |n|
467
+ parser.on(
468
+ "-cNUM",
469
+ "--copies=NUM",
470
+ Integer,
471
+ "Number of copies of each label to generate",
472
+ ) do |n|
388
473
  options.copies = n.abs
389
474
  warn " ::copies <- #{options.copies}::" if options.verbose
390
475
  end
@@ -393,8 +478,11 @@ module Labrat
393
478
  # For batch printing of labels, the user might want to just feed a file of
394
479
  # labels to be printed. This option allows a file name to be give.
395
480
  def in_file_option
396
- parser.on("-fFILENAME", "--in-file=FILENAME",
397
- "Read labels from given file instead of command-line") do |file|
481
+ parser.on(
482
+ "-fFILENAME",
483
+ "--in-file=FILENAME",
484
+ "Read labels from given file instead of command-line",
485
+ ) do |file|
398
486
  options.in_file = file.strip
399
487
  warn " ::in-file <- '#{file}'::" if options.verbose
400
488
  end
@@ -403,10 +491,13 @@ module Labrat
403
491
  # For batch printing of labels, the user might want to just feed a file of
404
492
  # labels to be printed. This option allows a file name to be give.
405
493
  def out_file_option
406
- parser.on("-oFILENAME", "--out-file=FILENAME",
407
- "Put generated label in the given file") do |file|
494
+ parser.on(
495
+ "-oFILENAME",
496
+ "--out-file=FILENAME",
497
+ "Put generated label in the given file",
498
+ ) do |file|
408
499
  file = file.strip
409
- unless file =~ /\.pdf\z/i
500
+ unless /\.pdf\z/i.match?(file)
410
501
  file = "#{file}.pdf"
411
502
  end
412
503
  options.out_file = file
@@ -416,14 +507,20 @@ module Labrat
416
507
 
417
508
  def command_options
418
509
  # NB: the % is supposed to remind me of the rollers on a printer
419
- parser.on("-%PRINTCMD", "--print-command=PRINTCMD",
420
- "Command to use for printing with %p for printer name; %o for label file name") do |cmd|
510
+ parser.on(
511
+ "-%PRINTCMD",
512
+ "--print-command=PRINTCMD",
513
+ "Command to use for printing with %p for printer name; %o for label file name",
514
+ ) do |cmd|
421
515
  options.print_command = cmd.strip
422
516
  warn " ::print-command <- '#{cmd}'::" if options.verbose
423
517
  end
424
518
  # NB: the : is supposed to remind me of two eyeballs viewing the PDF
425
- parser.on("-:VIEWCMD", "--view-command=VIEWCMD",
426
- "Command to use for viewing with %o for label file name") do |cmd|
519
+ parser.on(
520
+ "-:VIEWCMD",
521
+ "--view-command=VIEWCMD",
522
+ "Command to use for viewing with %o for label file name",
523
+ ) do |cmd|
427
524
  options.view_command = cmd.strip
428
525
  warn " ::view-command <- '#{cmd}'::" if options.verbose
429
526
  end
@@ -433,9 +530,12 @@ module Labrat
433
530
  # the text turned 90 degrees clockwise from the orientation the label has
434
531
  # coming out of the printer.
435
532
  def landscape_option
436
- parser.on("-L", "--[no-]landscape",
437
- "Orient label in landscape (default false), i.e., with the left of",
438
- "the label text starting at the top as the label as printed") do |l|
533
+ parser.on(
534
+ "-L",
535
+ "--[no-]landscape",
536
+ "Orient label in landscape (default false), i.e., with the left of",
537
+ "the label text starting at the top as the label as printed",
538
+ ) do |l|
439
539
  options.landscape = l
440
540
  warn " ::landscape <- #{l}::" if options.verbose
441
541
  end
@@ -443,9 +543,12 @@ module Labrat
443
543
 
444
544
  # The inverse of landscape, i.e., no rotation is done.
445
545
  def portrait_option
446
- parser.on("-P", "--[no-]portrait",
447
- "Orient label in portrait (default true), i.e., left-to-right",
448
- "top-to-bottom as the label as printed. Negated landscape") do |p|
546
+ parser.on(
547
+ "-P",
548
+ "--[no-]portrait",
549
+ "Orient label in portrait (default true), i.e., left-to-right",
550
+ "top-to-bottom as the label as printed. Negated landscape",
551
+ ) do |p|
449
552
  options.landscape = !p
450
553
  warn " portrait option executed as ::landscape <- #{!p}::" if options.verbose
451
554
  end
@@ -473,8 +576,11 @@ module Labrat
473
576
  # produce a template showing the boundaries of each label on a page of
474
577
  # labels.
475
578
  def template_option
476
- parser.on("-T", "--[no-]template",
477
- "Print a template of a page of labels and ignore any content.") do |t|
579
+ parser.on(
580
+ "-T",
581
+ "--[no-]template",
582
+ "Print a template of a page of labels and ignore any content.",
583
+ ) do |t|
478
584
  options.template = t
479
585
  warn " ::template <- #{t}::" if options.verbose
480
586
  end
data/lib/labrat/config.rb CHANGED
@@ -71,11 +71,11 @@ module Labrat
71
71
  files.each do |f|
72
72
  next unless File.readable?(f)
73
73
 
74
- yml_hash = YAML.load(File.read(f))
74
+ yml_hash = YAML.load_file(f)
75
75
  next unless yml_hash
76
76
 
77
77
  if yml_hash.is_a?(Hash)
78
- yml_hash = yml_hash.methodize
78
+ yml_hash = yml_hash
79
79
  else
80
80
  raise "Error loading file #{f}:\n#{File.read(f)[0..500]}"
81
81
  end
@@ -107,8 +107,13 @@ module Labrat
107
107
  dir = File.expand_path(File.join(dir, app_name))
108
108
  dir = File.join(dir_prefix, dir) unless dir_prefix.nil? || dir_prefix.strip.empty?
109
109
  base = app_name if base.nil? || base.strip.empty?
110
- base_candidates = [base.to_s, "#{base}.yml", "#{base}.yaml",
111
- "#{base}.cfg", "#{base}.config"]
110
+ base_candidates = [
111
+ base.to_s,
112
+ "#{base}.yml",
113
+ "#{base}.yaml",
114
+ "#{base}.cfg",
115
+ "#{base}.config"
116
+ ]
112
117
  config_fname = base_candidates.find { |b| File.readable?(File.join(dir, b)) }
113
118
  configs << File.join(dir, config_fname) if config_fname
114
119
  end
@@ -124,14 +129,19 @@ module Labrat
124
129
  # with dir_prefix if given.
125
130
  def self.find_xdg_user_config_file(app_name, base, dir_prefix)
126
131
  dir_prefix ||= ''
127
- base ||= (base&.strip || app_name)
132
+ base ||= base&.strip || app_name
128
133
  xdg_search_dir = ENV['XDG_CONFIG_HOME'] || ['~/.config']
129
134
  dir = File.expand_path(File.join(xdg_search_dir, app_name))
130
135
  dir = File.join(dir_prefix, dir) unless dir_prefix.strip.empty?
131
- return nil unless Dir.exist?(dir)
136
+ return unless Dir.exist?(dir)
132
137
 
133
- base_candidates = [base.to_s, "#{base}.yml", "#{base}.yaml",
134
- "#{base}.cfg", "#{base}.config"]
138
+ base_candidates = [
139
+ base.to_s,
140
+ "#{base}.yml",
141
+ "#{base}.yaml",
142
+ "#{base}.cfg",
143
+ "#{base}.config"
144
+ ]
135
145
  config_fname = base_candidates.find { |b| File.readable?(File.join(dir, b)) }
136
146
  if config_fname
137
147
  File.join(dir, config_fname)
@@ -160,8 +170,12 @@ module Labrat
160
170
  dir = File.join(dir_prefix, "/etc/#{app_name}")
161
171
  if Dir.exist?(dir)
162
172
  base = app_name if base.nil? || base.strip.empty?
163
- base_candidates = ["#{base}" "#{base}.yml", "#{base}.yaml",
164
- "#{base}.cfg", "#{base}.config"]
173
+ base_candidates = [
174
+ base.to_s + "#{base}.yml",
175
+ "#{base}.yaml",
176
+ "#{base}.cfg",
177
+ "#{base}.config"
178
+ ]
165
179
  config = base_candidates.find { |b| File.readable?(File.join(dir, b)) }
166
180
  configs = [File.join(dir, config)] if config
167
181
  end
@@ -184,8 +198,14 @@ module Labrat
184
198
  base_fname = base_candidates.find { |b| File.readable?(File.join(config_dir, b)) }
185
199
  config_fname = File.join(config_dir, base_fname)
186
200
  elsif Dir.exist?(config_dir = File.join(dir_prefix, File.expand_path('~/')))
187
- base_candidates = [".#{app_name}", ".#{app_name}rc", ".#{app_name}.yml", ".#{app_name}.yaml",
188
- ".#{app_name}.cfg", ".#{app_name}.config"]
201
+ base_candidates = [
202
+ ".#{app_name}",
203
+ ".#{app_name}rc",
204
+ ".#{app_name}.yml",
205
+ ".#{app_name}.yaml",
206
+ ".#{app_name}.cfg",
207
+ ".#{app_name}.config"
208
+ ]
189
209
  base_fname = base_candidates.find { |b| File.readable?(File.join(config_dir, b)) }
190
210
  config_fname = File.join(config_dir, base_fname)
191
211
  end
data/lib/labrat/hash.rb CHANGED
@@ -1,18 +1,12 @@
1
1
  # frozen_string_literal: true
2
- class Hash
3
- # Transform hash keys to symbols suitable for calling as methods, i.e.,
4
- # translate any hyphens to underscores. This is the form we want to keep
5
- # config hashes in Labrat.
6
- def methodize
7
- transform_keys { |k| k.to_s.gsub('-', '_').to_sym }
8
- end
9
2
 
3
+ class Hash
10
4
  # Convert the given Hash into a Array of Strings that represent an
11
5
  # equivalent set of command-line args and pass them into the #parse method.
12
6
  def optionize
13
7
  options = []
14
8
  each_pair do |k, v|
15
- key = k.to_s.gsub('_', '-')
9
+ key = k.to_s.tr('_', '-')
16
10
  options <<
17
11
  if [TrueClass, FalseClass].include?(v.class)
18
12
  v ? "--#{key}" : "--no-#{key}"