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.



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

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.



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

def bottom
  @bottom
end

#bottom_colourObject

Returns the value of attribute bottom_colour.



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

def bottom_colour
  @bottom_colour
end

#diagObject (readonly)

Returns the value of attribute diag.



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

def diag
  @diag
end

#diag_colourObject

Returns the value of attribute diag_colour.



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

def diag_colour
  @diag_colour
end

#leftObject

Returns the value of attribute left.



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

def left
  @left
end

#left_colourObject

Returns the value of attribute left_colour.



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

def left_colour
  @left_colour
end

#need_diag1Object

Returns the value of attribute need_diag1.



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

def need_diag1
  @need_diag1
end

#need_diag2Object

Returns the value of attribute need_diag2.



362
363
364
# File 'lib/surpass/formatting.rb', line 362

def need_diag2
  @need_diag2
end

#rightObject

Returns the value of attribute right.



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

def right
  @right
end

#right_colourObject

Returns the value of attribute right_colour.



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

def right_colour
  @right_colour
end

#topObject

Returns the value of attribute top.



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

def top
  @top
end

#top_colourObject

Returns the value of attribute top_colour.



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

def top_colour
  @top_colour
end

Class Method Details

.line_type_constantsObject



407
408
409
# File 'lib/surpass/formatting.rb', line 407

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

.line_type_directivesObject



403
404
405
# File 'lib/surpass/formatting.rb', line 403

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

.line_type_directives_hashObject



411
412
413
# File 'lib/surpass/formatting.rb', line 411

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

Instance Method Details

#all=(directives) ⇒ Object



436
437
438
439
440
441
# File 'lib/surpass/formatting.rb', line 436

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

#process_directives(directives) ⇒ Object



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
473
474
# File 'lib/surpass/formatting.rb', line 443

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