montoc 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b21f5056dce35ad19543567d62658917b4ca6fa
4
- data.tar.gz: b58dd2db4fcf5a0490735464a5b9737b63987c90
3
+ metadata.gz: 64032cbe3ce6bb3550e177855762814a6538b056
4
+ data.tar.gz: 960325a626edc2850bc4b4cee3f0d6277a402e87
5
5
  SHA512:
6
- metadata.gz: ae2d125bb40b28b0b47aa86ebd714bf94c559647f100266926513ffee98232ce74889c48ce29f9f884090a02b98dc4ca937a0f18ce266017c23aa3b5c85fc7df
7
- data.tar.gz: 14e7feb96ccee786040a67acfa94ad96166f7164702c8d890c23cf4e1598a7e8b9fe77700ce0eb827e88cbdded9fb955dbc3a5a8d8ee54fba8e917ae923e6cf5
6
+ metadata.gz: cc8e5b9ab88d4e75bf4b57c83d71e6a7f236f33ffd9da8eddc999d7faa41232f713c3ece848110a10bdcd0f943a022829793f822951ab18c739424f683502206
7
+ data.tar.gz: 7ca648a7c912437ee60c2143d136ec1a6dd72ee7fe4e97177eca82ef2cc2f87cc8c9f2681c531a104cdb10f0514cd2f593259045a189c55e7f716e56391682a7
data/.gitignore CHANGED
@@ -13,4 +13,5 @@
13
13
  *.so
14
14
  *.o
15
15
  *.a
16
+ *.gem
16
17
  mkmf.log
@@ -9,11 +9,9 @@ module Montoc
9
9
 
10
10
  def initialize text = ""
11
11
  @text = text
12
- @rows = rows
13
- @columns = columns
14
12
  @format = :virgin
15
13
  yield self if block_given?
16
- self.class.experience self
14
+ DocBox.know self
17
15
  end
18
16
 
19
17
  # Override Object#to_s, so that puts or other methods call this
@@ -25,15 +23,15 @@ module Montoc
25
23
  return @text
26
24
  end
27
25
 
28
- @@original_text = {}
29
- def self.experience docbox
26
+ @original_text = {}
27
+ def self.know docbox
30
28
  fresh_key = docbox.object_id.to_s(36).to_sym
31
- @@original_text[fresh_key] = docbox.instance_eval {@text}
29
+ @original_text[fresh_key] = docbox.instance_eval {@text}
32
30
  end
33
31
 
34
- def self.remember docbox
32
+ def self.recall docbox
35
33
  fresh_key = docbox.object_id.to_s(36).to_sym
36
- return @@original_text[fresh_key]
34
+ return @original_text[fresh_key]
37
35
  end
38
36
 
39
37
  def + string
@@ -46,22 +44,34 @@ module Montoc
46
44
 
47
45
  def text= string
48
46
  @text = string
49
- self.class.experience self
47
+ DocBox.know self
50
48
  end
51
49
 
52
50
  # Find the longest lines in text and return the first match.
53
51
  # to_s is called from the longest_line to avoid chomp being called
54
52
  # from nil, in the case of text = ""
55
- def longest_line remove_new_line_char = true
53
+ # @note Should be used when the @format is still in the :virgin state.
54
+ # @return [String] Return the first longest line in text
55
+ def longest_line
56
56
  longest_line = squeeze_space.lines.max_by(&:length)
57
- longest_line = longest_line.to_s.chomp if remove_new_line_char
57
+ longest_line = longest_line.to_s.chomp
58
58
  return longest_line
59
59
  end
60
60
 
61
+ # Find the number of lines in a text or the number of rows if you see
62
+ # it as a two dimensional matrix of chars.
63
+ # @return [Fixnum] Number of lines in a text
61
64
  def rows
62
65
  return @text.lines.length
63
66
  end
64
67
 
68
+ # Find the contents of a specific row or line of a text.
69
+ # @note The specified number should start from 1 to number of rows. It will
70
+ # return nil if it's more than the total number of rows and raise
71
+ # ArgumentError if lower than 1.
72
+ # @param row_no [Fixnum] Specific row number, between 1 and total number
73
+ # of rows.
74
+ # @return [String] Return line at specified row
65
75
  def row row_no = 1
66
76
  raise ArgumentError, "Row number cannot be lower than 1." \
67
77
  if row_no < 1
@@ -70,10 +80,22 @@ module Montoc
70
80
  return row_text
71
81
  end
72
82
 
83
+ # Find the length of the longest line or number of columns in a matricized
84
+ # text.
85
+ # @return [Fixnum] Number of columns in a text
73
86
  def columns
74
87
  return longest_line.length
75
88
  end
76
89
 
90
+ # Find the contents of a specific column of a text.
91
+ # @note Should be used in matricized text, otherwise it could return some
92
+ # nil even though the column number specified less than the longest line.
93
+ # The specified number should start from 1 to number of columns. It will
94
+ # return nil if it's more than the total number of columns and raise
95
+ # ArgumentError if lower than 1.
96
+ # @param col_no [Fixnum] Specific column number, between 1 and total number
97
+ # of rows.
98
+ # @return [String] Return string at specified column of matricized text
77
99
  def column col_no = 1
78
100
  raise ArgumentError, "Column number cannot be lower than 1." \
79
101
  if col_no < 1
@@ -88,18 +110,36 @@ module Montoc
88
110
  return column_text
89
111
  end
90
112
 
91
- def matricize align = :left, columns = 80
113
+ # Make the object plain text into a rectangular (two dimensional
114
+ # matrix) text by filling the empty spaces with spaces.
115
+ # @note This will do nothing if the text is already a matrix
116
+ # @param align [Symbol] The alignment or format state, the default
117
+ # is `:left`
118
+ # @param columns [Fixnum] Number of columns to which the plain text
119
+ # converted.
120
+ # @return [DocBox, nil] The DocBox object after the content/text made
121
+ # into matrix or nil if the text is already a matrix before this
122
+ # method called.
123
+ def matricize align = :left, column_width = 72
92
124
  if !matrix?
93
- reflow! columns
125
+ reflow! column_width
94
126
  method(align.id2name + "!").call
95
127
  end
96
128
  end
97
129
 
98
- def matricize! align = :left, columns = 80
130
+ # Force making/remaking an object text into a matrix no matter it's
131
+ # already a matrix or not.
132
+ # @param (see #matricize)
133
+ # @return [DocBox] The DocBox object after the content/text made into
134
+ # matrix.
135
+ def matricize! align = :left, column_width = 72
99
136
  squeeze_space!
100
- matricize align, columns
137
+ matricize align, column_width
101
138
  end
102
139
 
140
+ # Check if the object text is already a matrix.
141
+ # @return [Boolean] Return `true` if the text already a matrix and
142
+ # `false` if not.
103
143
  def matrix?
104
144
  @text.each_line do |line|
105
145
  return false if line.to_s.chomp.length != columns
@@ -107,7 +147,11 @@ module Montoc
107
147
  return true
108
148
  end
109
149
 
110
- def matrix align = :left, columns = 80
150
+ # Make two dimensional array of chars from the current object text
151
+ # @param (see #matricize)
152
+ # @return [Array] Return two dimensional array of chars from the
153
+ # current object text
154
+ def matrix align = :left, columns = 72
111
155
  matricize align, columns
112
156
  matrix_arr = []
113
157
  @text.each_line.with_index do |line, index|
@@ -118,7 +162,7 @@ module Montoc
118
162
 
119
163
  def virginize
120
164
  @format = :virgin
121
- @text = self.class.remember self
165
+ @text = DocBox.recall self
122
166
  return self
123
167
  end
124
168
 
@@ -127,18 +171,19 @@ module Montoc
127
171
  return false
128
172
  end
129
173
 
174
+
130
175
  def left
131
176
  new_text = squeeze_space.split("\n").map do |line|
132
177
  line = line.to_s.ljust columns
133
178
  end .join "\n"
134
- return self.class.new(new_text)
179
+ return DocBox.new(new_text)
135
180
  end
136
181
 
137
182
  def right
138
183
  new_text = squeeze_space.split("\n").map do |line|
139
184
  line = line.chomp.strip.rjust columns
140
185
  end .join "\n"
141
- return self.class.new(new_text)
186
+ return DocBox.new(new_text)
142
187
  end
143
188
 
144
189
  def center
@@ -146,7 +191,7 @@ module Montoc
146
191
  line = line.chomp.strip.rjust columns-(columns-line.length)/2
147
192
  line = line.ljust columns
148
193
  end .join "\n"
149
- return self.class.new(new_text)
194
+ return DocBox.new(new_text)
150
195
  end
151
196
 
152
197
  def squeeze_space
@@ -268,7 +313,7 @@ module Montoc
268
313
  newer_text.chomp!
269
314
 
270
315
  # return new object with new text
271
- return self.class.new(newer_text)
316
+ return DocBox.new(newer_text)
272
317
  end
273
318
 
274
319
  def justify! left_align_EOP = true
@@ -282,7 +327,7 @@ module Montoc
282
327
  return longest_word
283
328
  end
284
329
 
285
- def reflow column_width = `echo $COLUMNS`.to_i
330
+ def reflow column_width = 72
286
331
  raise ArgumentError, "Columns cannot be shorter than the longest word." \
287
332
  if columns < longest_word.length
288
333
  new_text = ""
@@ -308,15 +353,15 @@ module Montoc
308
353
  new_text = new_paragraph.join("\n")
309
354
 
310
355
  unless @format == :virgin
311
- new_text = self.class.new(new_text).method(@format).call.text
356
+ new_text = DocBox.new(new_text).method(@format).call.text
312
357
  else
313
- return self.class.new(new_text).left # default alignment
358
+ return DocBox.new(new_text).left # default alignment
314
359
  end
315
360
 
316
- return self.class.new(new_text)
361
+ return DocBox.new(new_text)
317
362
  end
318
363
 
319
- def reflow! column_width = `echo $COLUMNS`.to_i
364
+ def reflow! column_width = 72
320
365
  obj = reflow(column_width)
321
366
  @text = obj.text
322
367
  @format = obj.format
@@ -1,3 +1,3 @@
1
1
  module Montoc
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: montoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Setyadi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-12 00:00:00.000000000 Z
11
+ date: 2014-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler