mrtable 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d93194f7e7851b05c61792e0823c3db016f52845
4
- data.tar.gz: e1d7c78cc51c22a384cd4f4d074fca0cb84623c9
2
+ SHA256:
3
+ metadata.gz: 7711b008c019a09de1e61298ca4c2624f20dc92f1d2b9b191cae7280cc143c30
4
+ data.tar.gz: 1fdb63f01b04dfb452278910053ec123f779ccd759118a52aaa28b0ba1d158d9
5
5
  SHA512:
6
- metadata.gz: 35121c86b9a27f76a68b31220caa3d81cff9b4d7b7981169772a478402d87e0b534c4d284f74ba2377d862d3d92fd633775a7b0569e8649a315ba674aef7d981
7
- data.tar.gz: f5368f5e2d589c594e6494b717211542fb5fb6177d419f07549a35df79407789444a2cd27e495444b6b14b023d8492d67bb495d9af2d125f058685345b703e28
6
+ metadata.gz: 2ee852f53e5e26e693c5b664040fb3f48cf952a6fadb00e7e4a4aea7471295df99ce05ef76d7c741166cb5960847e457f9d322edc96fd17ae936fa9d9204aa96
7
+ data.tar.gz: d910720796be2e8747f7304959b85d43fdbb647bc5fa1f43d19b5733fddac2022da138fc08135dd0b4c44872a1638e1cea56c2def4447d9336d1d686e9374bda
@@ -1,3 +1,12 @@
1
+ # 0.0.4
2
+
3
+ - refactoring
4
+
5
+ ## Breaking changes
6
+
7
+ - `Mrtable.parse`
8
+ - Change return value type: Hash => Array
9
+
1
10
  # 0.0.3
2
11
 
3
12
  - feat: Complement lacking columns
@@ -14,13 +14,13 @@ module Mrtable
14
14
  # ci: column index
15
15
  # @return new table
16
16
  def map_col_with_ci
17
- new_rows = @rows.map { |cols|
17
+ new_rows = @rows.map do |cols|
18
18
  new_cols = []
19
19
  cols.each_with_index { |col, ci|
20
20
  new_cols << yield(col, ci)
21
21
  }
22
22
  new_cols
23
- }
23
+ end
24
24
 
25
25
  new_header_cols = []
26
26
  @header_cols.each_with_index { |col, ci|
@@ -32,15 +32,15 @@ module Mrtable
32
32
 
33
33
  def calc_maxlens
34
34
  num_cols = @rows[0].size
35
- maxlens = (0...num_cols).map { |ci|
35
+ maxlens = (0...num_cols).map do |ci|
36
36
  cols_at_ci = @rows.map { |cols| cols[ci] }
37
37
  if @header_cols
38
38
  cols_at_ci << @header_cols[ci]
39
39
  end
40
- cols_at_ci.map { |col|
41
- Mrtable.col_len(col)
42
- }.max
43
- }
40
+ cols_at_ci
41
+ .map { |col| Mrtable.col_len(col) }
42
+ .max
43
+ end
44
44
 
45
45
  # compatibility for GFM
46
46
  min_len = 3
@@ -65,17 +65,17 @@ module Mrtable
65
65
  end
66
66
 
67
67
  def self.complement_cols(cols, num_cols_max, val)
68
- (0...num_cols_max).map { |ci|
68
+ (0...num_cols_max).map do |ci|
69
69
  if ci < cols.size
70
70
  cols[ci]
71
71
  else
72
72
  val
73
73
  end
74
- }
74
+ end
75
75
  end
76
76
 
77
77
  def self.int?(s)
78
- /^\-?[\d,]+$/ =~ s
78
+ /^\-?[\d,]+$/.match?(s)
79
79
  end
80
80
 
81
81
  def self.pad_col(col, maxlen)
@@ -94,7 +94,7 @@ module Mrtable
94
94
 
95
95
  def self.pad_right(s, n)
96
96
  rest = n - col_len(s)
97
- if rest <= 0
97
+ if rest == 0
98
98
  return s
99
99
  end
100
100
  s + (" " * rest)
@@ -102,13 +102,13 @@ module Mrtable
102
102
 
103
103
  def self.pad_left(s, n)
104
104
  rest = n - col_len(s)
105
- if rest <= 0
105
+ if rest == 0
106
106
  return s
107
107
  end
108
108
  (" " * rest) + s
109
109
  end
110
110
 
111
- def self.serealize_col(col)
111
+ def self.serialize_col(col)
112
112
  if col.nil?
113
113
  return ""
114
114
  elsif col == ""
@@ -116,7 +116,7 @@ module Mrtable
116
116
  end
117
117
 
118
118
  ret = json_encode(col)
119
- if /^\s+/ =~ ret || /\s+$/ =~ ret || /^\-+$/ =~ ret
119
+ if /^\s+/.match?(ret) or /\s+$/.match?(ret) or /^\-+$/.match?(ret)
120
120
  ret = '"' + ret + '"'
121
121
  end
122
122
 
@@ -129,7 +129,7 @@ module Mrtable
129
129
 
130
130
  # 32-126(0x20-0x7E), 65377-65439(0xFF61-0xFF9F)
131
131
  def self.hankaku?(c)
132
- (/^[ -~。-゚]$/ =~ c) ? true : false
132
+ /^[ -~。-゚]$/.match?(c)
133
133
  end
134
134
 
135
135
  def self.json_encode(val)
@@ -144,7 +144,7 @@ module Mrtable
144
144
  end
145
145
 
146
146
  def self.json_decode(str)
147
- if /^".*"$/ =~ str
147
+ if /^".*"$/.match?(str)
148
148
  JSON.parse('[' + str + ']')[0]
149
149
  else
150
150
  JSON.parse('["' + str + '"]')[0]
@@ -162,21 +162,21 @@ module Mrtable
162
162
  end
163
163
 
164
164
  def self.split_row(line)
165
- line2 = line + " "
165
+ work_line = line + " "
166
166
  cols = []
167
167
  buf = ""
168
168
  pos = 2
169
169
  pos_delta = nil
170
170
 
171
- num_repeat_max = line2.size
171
+ num_repeat_max = work_line.size
172
172
  num_repeat_max.times do
173
- break if pos >= line2.size
173
+ break if pos >= work_line.size
174
174
  pos_delta = 1
175
- rest = line2[pos..-1]
176
- if /^ \| / =~ rest
175
+ rest = work_line[pos..-1]
176
+ if /^ \| /.match?(rest)
177
177
  cols << buf; buf = ""
178
178
  pos_delta = 3
179
- elsif /^\\/ =~ rest
179
+ elsif /^\\/.match?(rest)
180
180
  if rest[1] == "|"
181
181
  buf += rest[1]
182
182
  pos_delta = 2
@@ -194,12 +194,13 @@ module Mrtable
194
194
  end
195
195
 
196
196
  def self.parse(text, opts = {})
197
- lines = text.split(/\r?\n/)
198
- lines2 = lines.reject { |line|
199
- /^\s*$/ =~ line ||
200
- /^\| \-\-\-+ \|/ =~ line
201
- }
202
- rows = lines2.map { |line|
197
+ lines = text
198
+ .split(/\r?\n/)
199
+ .reject { |line|
200
+ /^\s*$/.match?(line) or
201
+ /^\| \-\-\-+ \|/.match?(line)
202
+ }
203
+ rows = lines.map { |line|
203
204
  split_row(line)
204
205
  }
205
206
  raw = Table.new rows[0], rows[1..-1]
@@ -212,29 +213,29 @@ module Mrtable
212
213
  parse_col col
213
214
  }
214
215
 
215
- if opts.has_key? :complement
216
+ if opts.key? :complement
216
217
  unless opts[:complement].is_a? String or opts[:complement].nil?
217
218
  raise "opts[:complement] must be String or nil"
218
219
  end
219
220
  parsed = parsed.complement opts[:complement]
220
221
  end
221
222
 
222
- {
223
- :header_cols => parsed.header_cols,
224
- :rows => parsed.rows
225
- }
223
+ [
224
+ parsed.header_cols,
225
+ parsed.rows
226
+ ]
226
227
  end
227
-
228
+
228
229
  def self.generate(header_cols, rows)
229
230
  table = Table.new(header_cols, rows)
230
231
 
231
- serealized = table.map_col_with_ci { |col, _|
232
- serealize_col col
232
+ serialized = table.map_col_with_ci { |col, _|
233
+ serialize_col col
233
234
  }
234
235
 
235
- maxlens = serealized.calc_maxlens()
236
+ maxlens = serialized.calc_maxlens()
236
237
 
237
- padded = serealized.map_col_with_ci { |col, ci|
238
+ padded = serialized.map_col_with_ci { |col, ci|
238
239
  pad_col col, maxlens[ci]
239
240
  }
240
241
 
@@ -244,6 +245,8 @@ module Mrtable
244
245
  lines += padded.rows.map { |cols|
245
246
  to_table_row(cols)
246
247
  }
247
- lines.map { |line| line + "\n" }.join("")
248
+ lines
249
+ .map { |line| line + "\n" }
250
+ .join("")
248
251
  end
249
252
  end
@@ -1,3 +1,3 @@
1
1
  module Mrtable
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mrtable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sonota88
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2019-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubyforge_project:
91
- rubygems_version: 2.6.8
90
+ rubygems_version: 3.0.1
92
91
  signing_key:
93
92
  specification_version: 4
94
93
  summary: machine readable table