monospace_text_formatter 0.0.2 → 0.0.3

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,3 +1,7 @@
1
+ 0.0.3 (February 18, 2012)
2
+ Fixed handling of non display length for horizontal alignment.
3
+ Minor refactorings.
4
+
1
5
  0.0.2 (February 18, 2012)
2
6
  Implemented Line and Box #inspect methods.
3
7
  Refactored Box class to make inheritance simpler.
@@ -99,8 +99,8 @@ module MonospaceTextFormatter
99
99
  Chunk.new(string)
100
100
  end
101
101
 
102
- def new_line(string, attrs={})
103
- Line.new(string, attrs)
102
+ def new_line(string_or_chunk, attrs={})
103
+ Line.new(string_or_chunk, attrs)
104
104
  end
105
105
 
106
106
  def aligned_all_lines
@@ -33,6 +33,11 @@ module MonospaceTextFormatter
33
33
  @display_length
34
34
  end
35
35
 
36
+ def non_display_length
37
+ slice_whole_remaining_string unless remaining_string.empty?
38
+ to_s.length - display_length
39
+ end
40
+
36
41
  def concat(string_or_chunk)
37
42
 
38
43
  if string_or_chunk.kind_of?(Chunk)
@@ -117,9 +122,9 @@ module MonospaceTextFormatter
117
122
  end
118
123
 
119
124
  def pop_atomic_chunk
120
- chunk = atomic_chunks.pop
121
- @display_length -= chunk.display_length
122
- chunk
125
+ atomic_chunk = atomic_chunks.pop
126
+ @display_length -= atomic_chunk.display_length
127
+ atomic_chunk
123
128
  end
124
129
 
125
130
  def unshift_atomic_chunk(atomic_chunk)
@@ -128,15 +133,15 @@ module MonospaceTextFormatter
128
133
  end
129
134
 
130
135
  def shift_atomic_chunk
131
- chunk = atomic_chunks.shift
132
- @display_length -= chunk.display_length
133
- chunk
136
+ atomic_chunk = atomic_chunks.shift
137
+ @display_length -= atomic_chunk.display_length
138
+ atomic_chunk
134
139
  end
135
140
 
136
141
  def delete_atomic_chunk_at(index)
137
- chunk = atomic_chunks.delete_at(index)
138
- @display_length -= chunk.display_length
139
- chunk
142
+ atomic_chunk = atomic_chunks.delete_at(index)
143
+ @display_length -= atomic_chunk.display_length
144
+ atomic_chunk
140
145
  end
141
146
 
142
147
  def retrieve_first_atomic_chunk
@@ -82,11 +82,11 @@ module MonospaceTextFormatter
82
82
  else
83
83
  case align
84
84
  when :left
85
- visible_chunk.to_s.ljust(@fixed_width, fill)
85
+ visible_chunk.to_s.ljust( @fixed_width + visible_chunk.non_display_length, fill)
86
86
  when :center
87
- visible_chunk.to_s.center(@fixed_width, fill)
87
+ visible_chunk.to_s.center(@fixed_width + visible_chunk.non_display_length, fill)
88
88
  when :right
89
- visible_chunk.to_s.rjust(@fixed_width, fill)
89
+ visible_chunk.to_s.rjust( @fixed_width + visible_chunk.non_display_length, fill)
90
90
  end
91
91
  end
92
92
  end
@@ -1,3 +1,3 @@
1
1
  module MonospaceTextFormatter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &75602160 !ruby/object:Gem::Requirement
16
+ requirement: &83233040 !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: *75602160
24
+ version_requirements: *83233040
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