Class: Borders

Inherits:
Object
  • Object
show all
Defined in:
lib/surpass/formatting.rb

Constant Summary collapse

NO_LINE =
0x00
THIN =
0x01
MEDIUM =
0x02
DASHED =
0x03
DOTTED =
0x04
THICK =
0x05
DOUBLE =
0x06
HAIR =
0x07
MEDIUM_DASHED =

The following for BIFF8

0x08
THIN_DASH_DOTTED =
0x09
MEDIUM_DASH_DOTTED =
0x0A
THIN_DASH_DOT_DOTTED =
0x0B
MEDIUM_DASH_DOT_DOTTED =
0x0C
SLANTED_MEDIUM_DASH_DOTTED =
0x0D
NEED_DIAG1 =
0x01
NEED_DIAG2 =
0x01
NO_NEED_DIAG1 =
0x00
NO_NEED_DIAG2 =
0x00
LINE_TYPE_DIRECTIVES =

Want to keep these sorted in this order, so need nested array instead of hash.

[
  ['none', NO_LINE],
  ['thin', THIN],
  ['medium', MEDIUM],
  ['dashed', DASHED],
  ['dotted', DOTTED],
  ['thick', THICK],
  ['double', DOUBLE],
  ['hair', HAIR],
  ['medium-dashed', MEDIUM_DASHED],
  ['thin-dash-dotted', THIN_DASH_DOTTED],
  ['medium-dash-dotted', MEDIUM_DASH_DOTTED],
  ['thin-dash-dot-dotted', THIN_DASH_DOT_DOTTED],
  ['medium-dash-dot-dotted', MEDIUM_DASH_DOT_DOTTED],
  ['slanted-medium-dash-dotted', SLANTED_MEDIUM_DASH_DOTTED]
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Borders

Returns a new instance of Borders.



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/surpass/formatting.rb', line 413

def initialize(hash = {})
  @left   = NO_LINE
  @right  = NO_LINE
  @top    = NO_LINE
  @bottom = NO_LINE
  @diag   = NO_LINE

  @left_colour   = 0x40
  @right_colour  = 0x40
  @top_colour    = 0x40
  @bottom_colour = 0x40
  @diag_colour   = 0x40

  @need_diag1 = NO_NEED_DIAG1
  @need_diag2 = NO_NEED_DIAG2
  
  hash.each do |k, v|
    self.send((k.to_s + '=').to_sym, v)
  end
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



350
351
352
# File 'lib/surpass/formatting.rb', line 350

def bottom
  @bottom
end

#bottom_colourObject

Returns the value of attribute bottom_colour.



356
357
358
# File 'lib/surpass/formatting.rb', line 356

def bottom_colour
  @bottom_colour
end

#diagObject (readonly)

Returns the value of attribute diag.



351
352
353
# File 'lib/surpass/formatting.rb', line 351

def diag
  @diag
end

#diag_colourObject

Returns the value of attribute diag_colour.



357
358
359
# File 'lib/surpass/formatting.rb', line 357

def diag_colour
  @diag_colour
end

#leftObject

Returns the value of attribute left.



347
348
349
# File 'lib/surpass/formatting.rb', line 347

def left
  @left
end

#left_colourObject

Returns the value of attribute left_colour.



353
354
355
# File 'lib/surpass/formatting.rb', line 353

def left_colour
  @left_colour
end

#need_diag1Object

Returns the value of attribute need_diag1.



359
360
361
# File 'lib/surpass/formatting.rb', line 359

def need_diag1
  @need_diag1
end

#need_diag2Object

Returns the value of attribute need_diag2.



360
361
362
# File 'lib/surpass/formatting.rb', line 360

def need_diag2
  @need_diag2
end

#rightObject

Returns the value of attribute right.



348
349
350
# File 'lib/surpass/formatting.rb', line 348

def right
  @right
end

#right_colourObject

Returns the value of attribute right_colour.



354
355
356
# File 'lib/surpass/formatting.rb', line 354

def right_colour
  @right_colour
end

#topObject

Returns the value of attribute top.



349
350
351
# File 'lib/surpass/formatting.rb', line 349

def top
  @top
end

#top_colourObject

Returns the value of attribute top_colour.



355
356
357
# File 'lib/surpass/formatting.rb', line 355

def top_colour
  @top_colour
end

Class Method Details

.line_type_constantsObject



405
406
407
# File 'lib/surpass/formatting.rb', line 405

def self.line_type_constants
  LINE_TYPE_DIRECTIVES.collect {|k, v| v}
end

.line_type_directivesObject



401
402
403
# File 'lib/surpass/formatting.rb', line 401

def self.line_type_directives
  LINE_TYPE_DIRECTIVES.collect {|k, v| k}
end

.line_type_directives_hashObject



409
410
411
# File 'lib/surpass/formatting.rb', line 409

def self.line_type_directives_hash
  Hash[*LINE_TYPE_DIRECTIVES.flatten]
end

Instance Method Details

#all=(directives) ⇒ Object



434
435
436
437
438
439
# File 'lib/surpass/formatting.rb', line 434

def all=(directives)
  self.left = directives
  self.right = directives
  self.top = directives
  self.bottom = directives
end

#process_directives(directives) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/surpass/formatting.rb', line 441

def process_directives(directives)
  if directives =~ /\s/
    args = directives.split
  else
    args = [directives] # there's just 1 here, stick it in an array
  end
  
  raise "no directives given to process_directives" if args.empty? # maybe don't need this, just get thin black border? but for development I want to know if this happens.
  raise "too many directives given to process_directives" if args.size > 2
  
  instructions = [THIN, Formatting::COLOURS['black']]
  args.each do |a|
    if Formatting::COLOURS.include?(a)
      instructions[1] = Formatting::COLOURS[a]
      next
    end
    
    if Borders.line_type_directives.include?(a)
      instructions[0] = Borders.line_type_directives_hash[a]
      next
    end
    
    if Borders.line_type_constants.include?(a)
      instructions[0] = a
      next
    end

    raise "I don't know how to format a border with #{a.inspect}."
  end

  instructions
end