ruport-wiki-table-formatter 0.1.0 → 0.2.0

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
2
  SHA256:
3
- metadata.gz: cbb609c0de7f3ecc62cbfcccc448a63ca295f0913aee64f45860fbfee72e4dc9
4
- data.tar.gz: f913326247bff8d30c6d0aadd125a9b371b738290d2a4afbcf0d29cf6da2a172
3
+ metadata.gz: 3ebff419b49dce91bb0b69182a864d7dc8e67b9a32b27a8732a9d8540cc23149
4
+ data.tar.gz: 8e713cf0ff944391ad834347cba312ec6e78a1f770f24e5084fcc3e3eeddc562
5
5
  SHA512:
6
- metadata.gz: bcea9f3935328cf7f6ca79b682d0e0098a634b3442339de1bbee60f70aef5219e29b67f7eda40422add6d8204f043195b5b62d32254177571b29c006ecfcb643
7
- data.tar.gz: e14c4c149c2e9b1bb00f6749a8aa57973a9994e1a7e90014b56a7d61c9ce17c52b820131c45db75536bb3a754f2671efc009516ed282440177da3ea3d54af446
6
+ metadata.gz: 7a4b7225c682f36b26afdfffd850435231ce0783f31bac0bc6136beb3695d1f24f7ade01e89ca0296f98e54ba1029faeea7578f3f01ce373dcff73b5cd949eae
7
+ data.tar.gz: 3450aa4d3651cf3c498cb38a60e58eb3ea328ce7f51a941d88b1926b2abf72ad17626c2ff20e9c917a2f928552d5ef50973a1923b6c0b971b56b0b723d73e020
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/ruport-wiki-table-formatter.svg)](https://badge.fury.io/rb/ruport-wiki-table-formatter)
1
2
  [![Build Status](https://travis-ci.org/taichi-ishitani/ruport-wiki-table-formatter.svg?branch=master)](https://travis-ci.org/taichi-ishitani/ruport-wiki-table-formatter)
2
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/f3b59dc0ae2f3d912ffc/maintainability)](https://codeclimate.com/github/taichi-ishitani/ruport-wiki-table-formatter/maintainability)
3
4
  [![codecov](https://codecov.io/gh/taichi-ishitani/ruport-wiki-table-formatter/branch/master/graph/badge.svg)](https://codecov.io/gh/taichi-ishitani/ruport-wiki-table-formatter)
@@ -9,7 +9,8 @@ module Ruport
9
9
  # Allowed values are :left, :center and :right. Default is :left.
10
10
  #
11
11
  # <tt>:column_alignments:</tt> Alignments for specific columns.
12
- # You can configure alignments by using Hash (key: column name, value: alignment)
12
+ # You can configure alignments by using
13
+ # Hash (key: column name, value: alignment)
13
14
  class Markdown < Ruport::Formatter
14
15
  renders :markdown, for: [Controller::Table]
15
16
 
@@ -18,30 +19,41 @@ module Ruport
18
19
  apply_table_format_template(template.table)
19
20
  end
20
21
 
21
- # Checks to ensure the table has non empty column_names.
22
- def prepare_table
23
- if data.column_names.empty?
24
- message = 'Can\'t output table without column names.'
25
- raise Ruport::FormatterError.new(message)
26
- end
27
- end
28
-
29
- # Uses the column names from the given Data::Table to generate a table header.
22
+ # Uses the column names from the given Data::Table to generate
23
+ # a table header.
24
+ # If no column names are given, first row will be
25
+ # treated as table header.
30
26
  def build_table_header
31
- build_md_row(output, data.column_names)
32
- build_md_row(output, alignment_strings(data.column_names))
27
+ names = column_names(data)
28
+ build_md_row(output, names)
29
+ build_md_row(output, alignment_strings(names))
33
30
  end
34
31
 
35
32
  # Generates body of Markdown table data.
36
33
  # Following characters will be replaced as escape.
37
- # | -> &#124;
38
- # newline code(\n) -> <br>
34
+ #
35
+ # * | -> &#124;
36
+ # * newline code(\\n) -> \<br>
39
37
  def build_table_body
40
- data.each { |row| build_md_row(output, row) }
38
+ body =
39
+ if data.column_names && !data.column_names.empty?
40
+ data
41
+ else
42
+ data[1..-1]
43
+ end
44
+ body.each { |row| build_md_row(output, row) }
41
45
  end
42
46
 
43
47
  private
44
48
 
49
+ def column_names(data)
50
+ if data.column_names && !data.column_names.empty?
51
+ data.column_names
52
+ else
53
+ data[0]
54
+ end
55
+ end
56
+
45
57
  def build_md_row(output, row)
46
58
  output << '|'
47
59
  output << row.to_a.map { |cell| escape(+cell.to_s) }.join('|')
@@ -3,6 +3,6 @@
3
3
  module Ruport
4
4
  module WikiTableFormatter
5
5
  # Version of Ruport::WikiTableFormatter
6
- VERSION = '0.1.0'
6
+ VERSION = '0.2.0'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruport-wiki-table-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taichi Ishitani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-13 00:00:00.000000000 Z
11
+ date: 2019-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruport