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.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +27 -0
- data/.github/workflows/ruby.yml +38 -0
- data/.rubocop.yml +177 -2
- data/Gemfile +11 -5
- data/Gemfile.lock +108 -70
- data/README.org +52 -39
- data/Rakefile +1 -1
- data/bin/labrat +0 -1
- data/labrat.gemspec +5 -13
- data/lib/config_files/labeldb.yml +17 -0
- data/lib/labrat/arg_parser.rb +202 -96
- data/lib/labrat/config.rb +32 -12
- data/lib/labrat/hash.rb +2 -8
- data/lib/labrat/label.rb +28 -12
- data/lib/labrat/label_db.rb +2 -2
- data/lib/labrat/options.rb +48 -22
- data/lib/labrat/read_files.rb +3 -2
- data/lib/labrat/version.rb +1 -1
- data/lib/labrat.rb +1 -0
- data/texlabels/sample.pdf +0 -0
- data/texlabels/sample.tex +9 -5
- metadata +17 -116
- data/texlabels/sample.synctex.gz +0 -0
    
        data/lib/labrat/arg_parser.rb
    CHANGED
    
    | @@ -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 | 
            -
             | 
| 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( | 
| 134 | 
            -
             | 
| 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( | 
| 138 | 
            -
             | 
| 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( | 
| 142 | 
            -
             | 
| 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( | 
| 147 | 
            -
             | 
| 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( | 
| 152 | 
            -
             | 
| 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( | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 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( | 
| 167 | 
            -
             | 
| 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( | 
| 171 | 
            -
             | 
| 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( | 
| 175 | 
            -
             | 
| 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( | 
| 179 | 
            -
             | 
| 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( | 
| 183 | 
            -
             | 
| 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( | 
| 187 | 
            -
             | 
| 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( | 
| 191 | 
            -
             | 
| 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( | 
| 203 | 
            -
             | 
| 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( | 
| 230 | 
            -
             | 
| 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  | 
| 245 | 
            -
                        nm | 
| 281 | 
            +
                      lab_names.sort_by { |nm|
         | 
| 282 | 
            +
                        nm =~ /\A([a-zA-Z]+)([0-9]+)?/
         | 
| 246 283 | 
             
                        [$1, $2.to_i || 0]
         | 
| 247 | 
            -
                       | 
| 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( | 
| 261 | 
            -
             | 
| 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( | 
| 266 | 
            -
             | 
| 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( | 
| 278 | 
            -
             | 
| 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( | 
| 282 | 
            -
             | 
| 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( | 
| 286 | 
            -
             | 
| 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( | 
| 290 | 
            -
             | 
| 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( | 
| 294 | 
            -
             | 
| 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( | 
| 298 | 
            -
             | 
| 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( | 
| 302 | 
            -
             | 
| 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( | 
| 311 | 
            -
             | 
| 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( | 
| 316 | 
            -
             | 
| 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( | 
| 321 | 
            -
             | 
| 322 | 
            -
             | 
| 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( | 
| 335 | 
            -
             | 
| 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( | 
| 339 | 
            -
             | 
| 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( | 
| 347 | 
            -
             | 
| 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( | 
| 355 | 
            -
             | 
| 356 | 
            -
             | 
| 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( | 
| 368 | 
            -
             | 
| 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( | 
| 379 | 
            -
             | 
| 380 | 
            -
                     | 
| 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( | 
| 387 | 
            -
             | 
| 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( | 
| 397 | 
            -
             | 
| 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( | 
| 407 | 
            -
             | 
| 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  | 
| 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( | 
| 420 | 
            -
             | 
| 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( | 
| 426 | 
            -
             | 
| 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( | 
| 437 | 
            -
             | 
| 438 | 
            -
             | 
| 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( | 
| 447 | 
            -
             | 
| 448 | 
            -
             | 
| 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( | 
| 477 | 
            -
             | 
| 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. | 
| 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 | 
| 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 = [ | 
| 111 | 
            -
             | 
| 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 ||=  | 
| 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  | 
| 136 | 
            +
                  return unless Dir.exist?(dir)
         | 
| 132 137 |  | 
| 133 | 
            -
                  base_candidates = [ | 
| 134 | 
            -
             | 
| 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 = [ | 
| 164 | 
            -
             | 
| 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 = [ | 
| 188 | 
            -
             | 
| 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. | 
| 9 | 
            +
                  key = k.to_s.tr('_', '-')
         | 
| 16 10 | 
             
                  options <<
         | 
| 17 11 | 
             
                    if [TrueClass, FalseClass].include?(v.class)
         | 
| 18 12 | 
             
                      v ? "--#{key}" : "--no-#{key}"
         |