Class: MonoclePrint::Graphics

Inherits:
Struct
  • Object
show all
Includes:
MonoclePrint
Defined in:
lib/monocle-print/graphics.rb,
lib/monocle-print/graphics.rb

Constant Summary collapse

NAMED_STYLES =
Hash.new { |h, k| h[ DEFAULT_STYLE ].dup  }
DEFAULT_STYLE =
default_style

Constants included from MonoclePrint

COLOR_ESCAPE, FOUR_BYTES, MULTIBYTE_CHARACTER, ONE_BYTE, THREE_BYTES, TWO_BYTES, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MonoclePrint

Line, Output, Rectangle, Style, Text, included, library_path, stdout, version

Instance Attribute Details

#blankObject

Returns the value of attribute blank

Returns:

  • (Object)

    the current value of blank



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def blank
  @blank
end

#enObject

Returns the value of attribute en

Returns:

  • (Object)

    the current value of en



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def en
  @en
end

#ensObject

Returns the value of attribute ens

Returns:

  • (Object)

    the current value of ens



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def ens
  @ens
end

#enswObject

Returns the value of attribute ensw

Returns:

  • (Object)

    the current value of ensw



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def ensw
  @ensw
end

#enwObject

Returns the value of attribute enw

Returns:

  • (Object)

    the current value of enw



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def enw
  @enw
end

#esObject

Returns the value of attribute es

Returns:

  • (Object)

    the current value of es



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def es
  @es
end

#eswObject

Returns the value of attribute esw

Returns:

  • (Object)

    the current value of esw



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def esw
  @esw
end

#ewObject Also known as: h

Returns the value of attribute ew

Returns:

  • (Object)

    the current value of ew



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def ew
  @ew
end

#nsObject Also known as: v

Returns the value of attribute ns

Returns:

  • (Object)

    the current value of ns



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def ns
  @ns
end

#nswObject

Returns the value of attribute nsw

Returns:

  • (Object)

    the current value of nsw



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def nsw
  @nsw
end

#nwObject

Returns the value of attribute nw

Returns:

  • (Object)

    the current value of nw



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def nw
  @nw
end

#swObject

Returns the value of attribute sw

Returns:

  • (Object)

    the current value of sw



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def sw
  @sw
end

#tree_forkObject

Returns the value of attribute tree_fork

Returns:

  • (Object)

    the current value of tree_fork



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def tree_fork
  @tree_fork
end

#tree_tailObject

Returns the value of attribute tree_tail

Returns:

  • (Object)

    the current value of tree_tail



6
7
8
# File 'lib/monocle-print/graphics.rb', line 6

def tree_tail
  @tree_tail
end

Class Method Details

.define(name, *parts) ⇒ Object



31
32
33
34
# File 'lib/monocle-print/graphics.rb', line 31

def self.define( name, *parts )
  parts.map! { | p | Line( p ).freeze }
  NAMED_STYLES[ name.to_s ] = new( *parts ).freeze
end

.stylesObject



27
28
29
# File 'lib/monocle-print/graphics.rb', line 27

def self.styles
  NAMED_STYLES.keys
end

Instance Method Details

#box_bottom(width) ⇒ Object



71
72
73
# File 'lib/monocle-print/graphics.rb', line 71

def box_bottom( width )
  format( "<ne><ew:#{ width }><nw>" )
end

#box_top(width) ⇒ Object



67
68
69
# File 'lib/monocle-print/graphics.rb', line 67

def box_top( width )
  format( "<se><ew:#{ width }><sw>" )
end

#format(description) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/monocle-print/graphics.rb', line 54

def format( description )
  out = Line( description )
  out.gsub!( /<([nsewlrtbudhv]+)(?::(\d+))?>/i ) do
    box_bit = resolve_name( $1 )
    $2 ? box_bit.tile( $2.to_i ) : box_bit
  end
  return( out )
end

#horizontal_line(width) ⇒ Object



63
64
65
# File 'lib/monocle-print/graphics.rb', line 63

def horizontal_line( width )
  ew.tile( width )
end

#line_with_joints(joint, *widths) ⇒ Object



87
88
89
# File 'lib/monocle-print/graphics.rb', line 87

def line_with_joints( joint, *widths )
  widths.map { | w | horizontal_line( w ) }.join( joint )
end

#table_bottom(*column_widths) ⇒ Object



83
84
85
# File 'lib/monocle-print/graphics.rb', line 83

def table_bottom( *column_widths )
  sw + line_with_joints( enw, column_widths ) + se
end

#table_divide(*column_widths) ⇒ Object



79
80
81
# File 'lib/monocle-print/graphics.rb', line 79

def table_divide( *column_widths )
  ens + line_with_joints( ensw, column_widths ) + nsw
end

#table_top(*column_widths) ⇒ Object



75
76
77
# File 'lib/monocle-print/graphics.rb', line 75

def table_top( *column_widths )
  nw + line_with_joints( esw, column_widths ) + ne
end