monospace_text_formatter 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog CHANGED
@@ -1,2 +1,6 @@
1
+ 0.0.2 (February 18, 2012)
2
+ Implemented Line and Box #inspect methods.
3
+ Refactored Box class to make inheritance simpler.
4
+
1
5
  0.0.1 (February 16, 2012)
2
6
  Initial release.
@@ -85,6 +85,10 @@ module MonospaceTextFormatter
85
85
  @to_s ||= lines.join("\n")
86
86
  end
87
87
 
88
+ def inspect
89
+ %Q(#<#{self.class} #{to_s.inspect}>)
90
+ end
91
+
88
92
  private
89
93
 
90
94
  def to_chunk_if_string(string)
@@ -95,6 +99,10 @@ module MonospaceTextFormatter
95
99
  Chunk.new(string)
96
100
  end
97
101
 
102
+ def new_line(string, attrs={})
103
+ Line.new(string, attrs)
104
+ end
105
+
98
106
  def aligned_all_lines
99
107
  @aligned_all_lines ||= all_lines.each do |line|
100
108
  line.attributes(:align => align, :fill => fill, :width => width)
@@ -111,9 +119,9 @@ module MonospaceTextFormatter
111
119
  when :top
112
120
  []
113
121
  when :middle
114
- Array.new(((@fixed_height - content_lines.size) / 2.0).floor, Line.new(""))
122
+ Array.new(((@fixed_height - content_lines.size) / 2.0).floor, new_line(""))
115
123
  when :bottom
116
- Array.new(@fixed_height - content_lines.size, Line.new(""))
124
+ Array.new(@fixed_height - content_lines.size, new_line(""))
117
125
  end
118
126
  else
119
127
  []
@@ -124,9 +132,9 @@ module MonospaceTextFormatter
124
132
  @empty_bottom_lines ||= if @fixed_height && fill && !fill.empty?
125
133
  case valign
126
134
  when :top
127
- Array.new(@fixed_height - content_lines.size, Line.new(""))
135
+ Array.new(@fixed_height - content_lines.size, new_line(""))
128
136
  when :middle
129
- Array.new(((@fixed_height - content_lines.size) / 2.0).ceil, Line.new(""))
137
+ Array.new(((@fixed_height - content_lines.size) / 2.0).ceil, new_line(""))
130
138
  when :bottom
131
139
  []
132
140
  end
@@ -138,7 +146,7 @@ module MonospaceTextFormatter
138
146
  def content_lines
139
147
  return @content_lines unless @content_lines.nil?
140
148
  return @content_lines = [] if @fixed_width == 0 && @fixed_height.nil?
141
- return @content_lines = [Line.new("")] if @original_chunk.empty?
149
+ return @content_lines = [new_line("")] if @original_chunk.empty?
142
150
 
143
151
  @remaining_chunk = @original_chunk.duplicate
144
152
  @line_chunks = []
@@ -152,7 +160,7 @@ module MonospaceTextFormatter
152
160
  end
153
161
 
154
162
  common_width = @fixed_width || @line_chunks.map { |chunk| chunk.display_length }.max
155
- @content_lines = @line_chunks.map { |chunk| Line.new(chunk, :width => common_width, :omission => omission) }
163
+ @content_lines = @line_chunks.map { |chunk| new_line(chunk, :width => common_width, :omission => omission) }
156
164
  end
157
165
  end
158
166
  end
@@ -62,6 +62,10 @@ module MonospaceTextFormatter
62
62
  aligned_visible_text
63
63
  end
64
64
 
65
+ def inspect
66
+ %Q(#<#{self.class} #{to_s.inspect}>)
67
+ end
68
+
65
69
  private
66
70
 
67
71
  def to_chunk_if_string(string)
@@ -1,3 +1,3 @@
1
1
  module MonospaceTextFormatter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monospace_text_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-16 00:00:00.000000000Z
12
+ date: 2012-02-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70478590 !ruby/object:Gem::Requirement
16
+ requirement: &75602160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70478590
24
+ version_requirements: *75602160
25
25
  description: Formats monospaced text into a line or visual box of defined 'width'
26
26
  and 'height' boundaries (expressed in number of characters).
27
27
  email: jacekmikrut.software@gmail.com