monocle-print 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTJhOTg2ZGRkZTUzMDYxOTAxMmNhMWI2ZTJjM2ViM2E0NTk4YzBmMQ==
4
+ MGVhMTAyZWIyYjRmMzdlMjJlNzkzNDM5MjdmYzExOWYxODA5YjFlMg==
5
5
  data.tar.gz: !binary |-
6
- NmMyYWJmNzEyZDc1ZWZlODE5NDgwY2RiNjI1NDAzYjdjYzdhNWY1OA==
6
+ OWFiZWYxNzUzYjgwZmFhZDU0OWI2ZDIyMzRmMDU4MWQ5MzgzMTFjNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDE0ZDQwOTk5MTk1ZDVkYjM5NjJjZjg3OGFmZWVlMmRhMTFkOTcxMWNkNDgz
10
- ODExMTQ5ODFmMzkxZTgxMTNlYmExODUzY2M1MWZlODE4MTlmNWY2NTViYzY5
11
- ZmM3ZjZjNGZiZTU3YzI4ZmYwNTQzNDc0ODEwNGQ2ZDE5OTkyZjE=
9
+ ZjAyNzQzNDAxMmVhMTYxYmVmZjgwNzlkYmI2ZWU4OWZiMzE4MjQ3NjQ1YjIz
10
+ ZTkxNDYyY2MzYjA0MDlkMDc4OGQ5ZjFhMjNjMjFkMTVmZWQxNjgxYzllNTRm
11
+ MjQwNTQ1NTJjYzc4NDkxNWZlZWE2ZDFhNTg1ZTkzNGQyOTVlM2Q=
12
12
  data.tar.gz: !binary |-
13
- MGUyN2Q0NzkyN2I5ZWY0NjUzNzE2NWRlNDc3MTg4NGE2NDRiMDZjMjAzZDlm
14
- YWZjM2Q2YzkyNWMzNWJiZDcyZmNjYzUyNTliMmJlY2U0ZmFiNzRjNDUwNjNk
15
- YzRlNmJmMWQ0MGE5MjQ0NjM0ODk3MjRjODg0MzQ2ZWNkNzFmOGI=
13
+ MjIzZDUyODIzNGU1Yzc0ODc5ODkwMzQ4NTJlMjNjMmZmNGFiNTc3ZTdlMDE2
14
+ ZGUxM2QwZDllZTFlNDFjMDk2NTExZTQzNzY4OTUyZWRmOTdiMDhjMDRhYjBl
15
+ MTc5YmY3ZDA5NGFiMTEwMjMzMjRlYTA0ZmE3ZjFjMjdmMDhmODg=
data/lib/monocle-print.rb CHANGED
@@ -7,8 +7,11 @@ rescue LoadError
7
7
  # ignore
8
8
  end
9
9
 
10
+ require 'delegate'
11
+ autoload :StringIO, 'stringio' unless defined?( StringIO )
12
+
10
13
  module MonoclePrint
11
- VERSION = '1.0.2'
14
+ VERSION = '1.0.4'
12
15
 
13
16
  def self.version
14
17
  VERSION
@@ -54,7 +57,7 @@ module_function
54
57
  end
55
58
 
56
59
  def Style( obj )
57
- Graphics === obj ? obj : Graphics::NAMED_STYLES[ obj.to_s ]
60
+ Graphics === obj ? obj : Graphics.style( obj )
58
61
  end
59
62
 
60
63
  def Rectangle( obj )
@@ -1,56 +1,36 @@
1
1
  #!/usr/bin/ruby
2
2
  # encoding: utf-8
3
3
 
4
+ require 'monocle-print/graphics/registry'
4
5
 
5
6
  module MonoclePrint
6
- Graphics = Struct.new(
7
- :ew, # west east - horizontal line
8
- :ns, # north south - vertical line
9
- :es, # north west - top right corner
10
- :sw, # north east
11
- :nw, # south east
12
- :en, # south west
13
- :ens, # north south east
14
- :nsw, # north south west
15
- :enw, # east north west
16
- :esw, # east south west
17
- :ensw, # east north south west - intersection of horiz & vertical lines
18
- :tree_fork,
19
- :tree_tail,
20
- :blank
21
- )
7
+ Graphics =
8
+ Struct.new(
9
+ :ew, # west east - horizontal line
10
+ :ns, # north south - vertical line
11
+ :es, # north west - top right corner
12
+ :sw, # north east
13
+ :nw, # south east
14
+ :en, # south west
15
+ :ens, # north south east
16
+ :nsw, # north south west
17
+ :enw, # east north west
18
+ :esw, # east south west
19
+ :ensw, # east north south west - intersection of horiz & vertical lines
20
+ :tree_fork,
21
+ :tree_tail,
22
+ :blank
23
+ )
22
24
 
23
25
  class Graphics
24
26
  include MonoclePrint
25
- NAMED_STYLES = Hash.new { |h, k| h[ DEFAULT_STYLE ].dup }
26
-
27
- def self.styles
28
- NAMED_STYLES.keys
29
- end
30
-
31
- def self.define( name, *parts )
32
- parts.map! { | p | Line( p ).freeze }
33
- NAMED_STYLES[ name.to_s ] = new( *parts ).freeze
34
- end
35
-
27
+ extend GraphicsRegistry
28
+
36
29
  define :blank, '', '', '', '', '', '', '', '', '', '', '', '', ''
37
30
  define :ascii, '-', '|', '+', '+', '+', '+', '+', '+', '+', '+', '+', '|', '`'
38
31
  define :single_line, '─', '│', '┌', '┐', '┘', '└', '├', '┤', '┴', '┬', '┼', '├', '└'
39
32
  define :double_line, '═', '║', '╔', '╗', '╝', '╚', '╠', '╣', '╩', '╦', '╬', '╠', '╚'
40
-
41
- default_style = ENV.fetch( 'MONOCLE_PRINT_STYLE', 'ascii' )
42
- unless styles.include?( default_style )
43
- message = <<-END.gsub!( /^\s*\| ?/, '' ).strip!.gsub!( /\s+/, ' ' )
44
- | cannot set MonoclePrint's default graphics style
45
- | from the MONOCLE_PRINT_STYLE environment variable as `%p'
46
- | is not a known style; defaulting to `ascii'
47
- END
48
- warn( message % default_style )
49
- default_style = 'ascii'
50
- end
51
-
52
- DEFAULT_STYLE = default_style
53
-
33
+
54
34
  def format( description )
55
35
  out = Line( description )
56
36
  out.gsub!( /<([nsewlrtbudhv]+)(?::(\d+))?>/i ) do
@@ -59,41 +39,40 @@ class Graphics
59
39
  end
60
40
  return( out )
61
41
  end
62
-
42
+
63
43
  def horizontal_line( width )
64
44
  ew.tile( width )
65
45
  end
66
-
46
+
67
47
  def box_top( width )
68
48
  format( "<se><ew:#{ width }><sw>" )
69
49
  end
70
-
50
+
71
51
  def box_bottom( width )
72
52
  format( "<ne><ew:#{ width }><nw>" )
73
53
  end
74
-
54
+
75
55
  def table_top( *column_widths )
76
56
  nw + line_with_joints( esw, column_widths ) + ne
77
57
  end
78
-
58
+
79
59
  def table_divide( *column_widths )
80
60
  ens + line_with_joints( ensw, column_widths ) + nsw
81
61
  end
82
-
62
+
83
63
  def table_bottom( *column_widths )
84
64
  sw + line_with_joints( enw, column_widths ) + se
85
65
  end
86
-
66
+
87
67
  def line_with_joints( joint, *widths )
88
68
  widths.map { | w | horizontal_line( w ) }.join( joint )
89
69
  end
90
-
70
+
91
71
  alias h ew
92
72
  alias v ns
93
-
94
-
95
- private
96
-
73
+
74
+ private
75
+
97
76
  def resolve_name( name )
98
77
  name.downcase!
99
78
  name.tr!( 'lrtbud', 'wensns' )
@@ -103,9 +82,5 @@ private
103
82
  chars.uniq!
104
83
  self[ chars.join('') ]
105
84
  end
106
-
107
-
108
-
109
85
  end
110
-
111
86
  end
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/ruby
2
2
  # encoding: utf-8
3
3
 
4
- require 'delegate'
5
- autoload :StringIO, 'stringio' unless defined?( StringIO )
6
4
 
7
5
  module MonoclePrint
8
6
  class OutputDevice < DelegateClass( IO )
@@ -424,8 +422,8 @@ private
424
422
  detected_height, detected_width = size.height, size.width
425
423
  end
426
424
  Pair.new(
427
- @forced_height || detected_height,
428
- @forced_width || detected_width
425
+ @forced_width || detected_width,
426
+ @forced_height || detected_height
429
427
  )
430
428
  rescue Exception
431
429
  default_size
@@ -10,7 +10,7 @@ module Presentation
10
10
  super
11
11
  klass.extend( ClassMethods )
12
12
  end
13
-
13
+
14
14
  attr_accessor :owner
15
15
  protected :owner=
16
16
 
@@ -41,7 +41,7 @@ module Presentation
41
41
 
42
42
  def style( value = nil )
43
43
  value and self.style = value
44
- @style or @owner ? @owner.style : Graphics::NAMED_STYLES[ 'ascii' ]
44
+ @style or @owner ? @owner.style : Graphics.default
45
45
  end
46
46
 
47
47
  def style= value
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monocle-print
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - monocle-print