Class: Pattern

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

Constant Summary collapse

NO_PATTERN =
0x00
SOLID_FOREGROUND =
0x01
SOLID_PATTERN =

for backwards compatibility

SOLID_FOREGROUND
FINE_DOTS =
0x02
ALT_BARS =
0x03
SPARSE_DOTS =
0x04
THICK_HORZ_BANDS =
0x05
THICK_VERT_BANDS =
0x06
THICK_BACKWARD_DIAG =
0x07
THICK_FORWARD_DIAG =
0x08
BIG_SPOTS =
0x09
BRICKS =
0x0A
THIN_HORZ_BANDS =
0x0B
THIN_VERT_BANDS =
0x0C
THIN_BACKWARD_DIAG =
0x0D
THIN_FORWARD_DIAG =
0x0E
SQUARES =
0x0F
DIAMONDS =
0x10
LESS_DOTS =
0x11
LEAST_DOTS =
0x12
PATTERN_DIRECTIVES =

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

[
  ['none', NO_PATTERN],
  ['solid', SOLID_FOREGROUND],
  ['fine-dots', FINE_DOTS],
  ['alt-bars', ALT_BARS],
  ['sparse-dots', SPARSE_DOTS],
  ['thick-horz-bands', THICK_HORZ_BANDS],
  ['thick-vert-bands', THICK_VERT_BANDS],
  ['thick-backward-diag', THICK_BACKWARD_DIAG],
  ['thick-forward-diag', THICK_FORWARD_DIAG],
  ['big-spots', BIG_SPOTS],
  ['bricks', BRICKS],
  ['thin-horz-bands', THIN_HORZ_BANDS],
  ['thin-vert-bands', THIN_VERT_BANDS],
  ['thin-backward-diag', THIN_BACKWARD_DIAG],
  ['thin-forward-diag', THIN_FORWARD_DIAG],
  ['squares', SQUARES],
  ['diamonds', DIAMONDS],
  ['less-dots', LESS_DOTS],
  ['least-dots', LEAST_DOTS]
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Pattern

Returns a new instance of Pattern.



551
552
553
554
555
556
557
558
559
# File 'lib/surpass/formatting.rb', line 551

def initialize(hash = {})
  @pattern = NO_PATTERN
  @pattern_fore_colour = 0x40
  @pattern_back_colour = 0x41
  
  hash.each do |k, v|
    self.send((k.to_s + '=').to_sym, v)
  end
end

Instance Attribute Details

#patternObject

Returns the value of attribute pattern.



539
540
541
# File 'lib/surpass/formatting.rb', line 539

def pattern
  @pattern
end

#pattern_back_colourObject (readonly)

Returns the value of attribute pattern_back_colour.



541
542
543
# File 'lib/surpass/formatting.rb', line 541

def pattern_back_colour
  @pattern_back_colour
end

#pattern_fore_colourObject (readonly)

Returns the value of attribute pattern_fore_colour.



540
541
542
# File 'lib/surpass/formatting.rb', line 540

def pattern_fore_colour
  @pattern_fore_colour
end

Class Method Details

.directives_hashObject



547
548
549
# File 'lib/surpass/formatting.rb', line 547

def self.directives_hash
  Hash[*PATTERN_DIRECTIVES.flatten]
end

.fill_directivesObject



543
544
545
# File 'lib/surpass/formatting.rb', line 543

def self.fill_directives
  PATTERN_DIRECTIVES.collect {|a| a[0]}
end

Instance Method Details

#back_colour=(arg) ⇒ Object Also known as: back_color=



582
583
584
585
586
# File 'lib/surpass/formatting.rb', line 582

def back_colour=(arg)
 colour_index = Formatting::COLOURS[arg]
 raise "Invalid colour #{arg}" if colour_index.nil?
 @pattern_back_colour = colour_index
end

#colour=(arg) ⇒ Object Also known as: color=, fill=

Sets the foreground colour, also if no pattern has been specified will assume you want a solid colour fill.



591
592
593
594
# File 'lib/surpass/formatting.rb', line 591

def colour=(arg)
  self.fore_colour = arg
  @pattern = SOLID_PATTERN if @pattern == NO_PATTERN
end

#fore_colour=(arg) ⇒ Object Also known as: fore_color=



575
576
577
578
579
# File 'lib/surpass/formatting.rb', line 575

def fore_colour=(arg)
 colour_index = Formatting::COLOURS[arg]
 raise "Invalid colour #{arg}" if colour_index.nil?
 @pattern_fore_colour = colour_index
end