marktable 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4dc7dda731d7cbac0c2b155c3c572c44954ca2f65281f3cf976b05ba9cd1532
4
- data.tar.gz: 1261f5a0afd0bbf45a16d8e9d369ef61b8e9313e83788a1b5e10be8871fac962
3
+ metadata.gz: e7f873538494ff9b1c7c9a5f74b25560c0a329e13ae77ab2648cedbe46dba1e7
4
+ data.tar.gz: 0bfc592905ad86578cf9fcfd953ffd589aebada3120d1f460e0c61818a5bea44
5
5
  SHA512:
6
- metadata.gz: 8127ab236b08a55f8d8d2fafcb116996d347527085af2dc1e71632b55930d326eae6e6b8bbac2e55c33965effa4d14863b4741e80c70297b2079bf715153dab6
7
- data.tar.gz: 8400c3fbb70a9330d2db6c36f23599161ae35e4766c614597f773f38305ae9bf62708d053477d5e727d7cf51dee76490bb23743c0c77aca76a4a87997795e9be
6
+ metadata.gz: da0ff6b0f29523c3b7cd99d31fe08d4cf0c79fb52bca4eb2603096396c560cf1734bf33b21990ba449c73a3b476d71d9985c62e743e8cd3525bd72d45c605937
7
+ data.tar.gz: cb6f9e8813e96393110f52a591d7a61a5b4e66d407db33fee2a8a52f347a934cb9586838d801195248b441b8999cee817819bfda83410faf7db0ff48d2738d0b
data/README.md CHANGED
@@ -1,27 +1,26 @@
1
1
  # Marktable
2
2
 
3
+ Marktable is a Ruby gem for easily converting between different table formats and testing table content in your specs.
3
4
 
4
- A powerful Ruby library for parsing, manipulating, and generating Markdown tables with an elegant and intuitive API.
5
+ ## Table of Contents
5
6
 
6
- ## 📚 Overview
7
+ - [Features](#features)
8
+ - [Installation](#installation)
9
+ - [Basic Usage](#basic-usage)
10
+ - [Documentation](#documentation)
11
+ - [License](#license)
7
12
 
8
- Marktable allows you to seamlessly work with Markdown tables using familiar Ruby data structures. Whether you're parsing tables from Markdown documents, generating tables for documentation, or manipulating tabular data, Marktable provides simple yet powerful tools for all your Markdown table needs.
13
+ ## Features
9
14
 
10
- ## Features
15
+ * RSpec matchers to compare tables across formats
16
+ * Convert between multiple table formats:
17
+ - Markdown tables
18
+ - Arrays of arrays
19
+ - Arrays of hashes
20
+ - CSV
21
+ - HTML tables
11
22
 
12
- - **Custom RSpec matcher** for testing Markdown-like data structures (including html tables) against expected Markdown output
13
- - **Parse** Markdown tables into Ruby data structures (arrays or hashes)
14
- - **Generate** beautifully formatted Markdown tables from Ruby objects
15
- - **Filter** and **transform** table data with Ruby's familiar block syntax
16
- - **Auto-detect** headers from properly formatted Markdown tables
17
- - **Handle** tables with or without headers
18
- - **Support** for mismatched columns and keys in data
19
- - **Convert** between array-based and hash-based representations
20
-
21
- ## Not supported
22
- - Non-string values (E.g. complex objects) in the table rows.
23
-
24
- ## 📦 Installation
23
+ ## Installation
25
24
 
26
25
  Add this line to your application's Gemfile:
27
26
 
@@ -31,343 +30,59 @@ gem 'marktable'
31
30
 
32
31
  And then execute:
33
32
 
34
- ```bash
35
- bundle install
36
- ```
37
-
38
- Or install it yourself as:
39
-
40
- ```bash
41
- gem install marktable
42
- ```
43
-
44
- ## 🚀 Quick Start
45
-
46
- ### Main use case (Rspec only at this time)
47
-
48
- This gem started as a pet project aiming at:
49
- - Simplifying the process of testing html table content
50
- - Making these specs more developer-friendly, with a very readable format
51
-
52
-
53
- ```ruby
54
- visit my_path
55
- actual_table = page.find('#my-table')
56
- expected_table = <<~MARKDOWN
57
- | Name | Age | City |
58
- | ----- | --- | -------- |
59
- | John | 30 | New York |
60
- | Jane | 25 | Boston |
61
- | Bob | 17 | Chicago |
62
- MARKDOWN
63
-
64
- expect(actual_table).to match_markdown(expected_table)
65
- ```
66
-
67
- In case of semantical mismatch, the matcher will show an easy to verify markdown representation of the tables:
68
-
69
- ```markdown
70
- Expected markdown table to match:
71
-
72
- Expected:
73
- | Name | Age | City |
74
- | ----- | --- | -------- |
75
- | John | 30 | New York |
76
- | Jane | 25 | Boston |
77
- | Bob | 17 | Chicago |
78
-
79
- Actual:
80
- | Name | Age |
81
- | ---- | --- |
82
- | John | 31 |
83
- | Jane | 25 |
84
-
85
- Parsed expected data: [{"Name" => "John", "Age" => "30"}, {"Name" => "Jane", "Age" => "25"}, {"Name" => "Bob", "Age" => "17"}]
86
- Parsed actual data: [{"Name" => "John", "Age" => "31"}, {"Name" => "Jane", "Age" => "25"}]
87
33
  ```
88
-
89
-
90
-
91
- ### Parsing a Markdown Table
92
-
93
- ```ruby
94
- require 'marktable'
95
-
96
- markdown_table = <<~MARKDOWN
97
- | Name | Age | City |
98
- | ----- | --- | -------- |
99
- | John | 30 | New York |
100
- | Jane | 25 | Boston |
101
- MARKDOWN
102
-
103
- # Parse into an array of hashes (with auto-detected headers)
104
- data = Marktable.parse(markdown_table)
105
- # => [
106
- # {"Name"=>"John", "Age"=>"30", "City"=>"New York"},
107
- # {"Name"=>"Jane", "Age"=>"25", "City"=>"Boston"}
108
- # ]
109
-
110
- # Access data easily
111
- puts data.first["Name"] # => "John"
34
+ $ bundle install
112
35
  ```
113
36
 
114
- ### Generating a Markdown Table
115
-
116
- ```ruby
117
- # Create a new table and add rows
118
- table = Marktable.generate do |t|
119
- t << {"Name" => "John", "Age" => "30", "City" => "New York"}
120
- t << {"Name" => "Jane", "Age" => "25", "City" => "Boston"}
121
- t << {"Name" => "Bob", "Age" => "17", "City" => "Chicago"}
122
- end
37
+ Or install it yourself:
123
38
 
124
- puts table
125
- # | Name | Age | City |
126
- # | ---- | --- | -------- |
127
- # | John | 30 | New York |
128
- # | Jane | 25 | Boston |
129
- # | Bob | 17 | Chicago |
130
39
  ```
131
-
132
- ## 📖 Usage Guide
133
-
134
- ### Working with Table Objects
135
-
136
- Create a table object for more advanced operations:
137
-
138
- ```ruby
139
- # Create from a markdown string
140
- table = Marktable.new(markdown_table)
141
-
142
- # Or create from array data
143
- array_data = [
144
- ["Name", "Age", "City"],
145
- ["John", "30", "New York"],
146
- ["Jane", "25", "Boston"],
147
- ["Bob", "17", "Chicago"]
148
- ]
149
- table = Marktable.new(array_data, headers: true)
150
-
151
- # Or with auto-detected headers
152
- array_data = [
153
- { "Name" => "John", "Age" => "30", "City" => "New York" },
154
- { "Name" => "Jane", "Age" => "25", "City" => "Boston" },
155
- { "Name" => "Bob", "Age" => "17", "City" => "Chicago" }
156
- ]
157
- table = Marktable.new(array_data)
40
+ $ gem install marktable
158
41
  ```
159
42
 
160
- ### Filtering Rows
43
+ ## Basic Usage
161
44
 
162
- Filter rows using pattern matching or blocks:
163
-
164
- ```ruby
165
- # Filter with a regex pattern
166
- nyc_residents = table.filter(/New York/)
167
-
168
- # Filter with a block
169
- adults = table.filter do |row|
170
- row["Age"].to_i >= 18
171
- end
172
-
173
- puts adults
174
- # | Name | Age | City |
175
- # | ---- | --- | -------- |
176
- # | John | 30 | New York |
177
- # | Jane | 25 | Boston |
178
- ```
179
-
180
- ### Transforming Data
181
-
182
- Transform table data with the map method:
183
-
184
- ```ruby
185
- # Add 5 years to everyone's age
186
- older = table.map do |row|
187
- row.merge("Age" => (row["Age"].to_i + 5).to_s)
188
- end
189
-
190
- puts older
191
- # | Name | Age | City |
192
- # | ---- | --- | -------- |
193
- # | John | 35 | New York |
194
- # | Jane | 30 | Boston |
195
- # | Bob | 22 | Chicago |
196
- ```
197
-
198
- ### Working with Arrays
199
-
200
- Use arrays instead of hashes for row data:
201
-
202
- ```ruby
203
- # Create a table with array rows
204
- table = Marktable.new([], headers: false)
205
- table << ["John", "30", "New York"]
206
- table << ["Jane", "25", "Boston"]
207
-
208
- puts table
209
- # | John | 30 | New York |
210
- # | Jane | 25 | Boston |
211
- ```
212
-
213
- ### Mixed Row Types
214
-
215
- Marktable can handle mixed row types (arrays and hashes):
216
-
217
- ```ruby
218
- table = Marktable.generate do |t|
219
- t << {"Name" => "John", "Age" => "30", "City" => "New York"}
220
- t << ["Jane", "25", "Boston"] # Array with same column count
221
- end
222
-
223
- puts table
224
- # | Name | Age | City |
225
- # | ---- | --- | -------- |
226
- # | John | 30 | New York |
227
- # | Jane | 25 | Boston |
228
- ```
229
-
230
- ## 🧪 Testing with Custom Matchers
231
-
232
- Marktable includes a custom RSpec matcher, `match_markdown`, to make testing Markdown-compatible data structures simple and reliable.
233
-
234
- ### Using the `match_markdown` Matcher
235
-
236
- First, require the matcher in your spec_helper.rb or in the specific test file:
45
+ ### RSpec Matchers
237
46
 
238
47
  ```ruby
48
+ # In your spec_helper.rb
239
49
  require 'marktable/rspec'
240
- ```
241
50
 
242
- #### Testing Markdown Table Output
51
+ # In your specs - compare tables across formats
52
+ expect(markdown_table).to match_markdown(expected_markdown)
243
53
 
244
- ```ruby
245
- RSpec.describe ReportGenerator do
246
- describe "#generate_customer_table" do
247
- it "generates the expected customer table" do
248
- actual = ReportGenerator.new(customers).generate_table
249
- # Presume actual contains:
250
- # [
251
- # { id: 1, name: "John Smith", status: "Active" },
252
- # { id: 2, name: "Jane Doe", status: "Pending" }
253
- # ]
254
-
255
- expected = <<~MARKDOWN
256
- | ID | Name | Status |
257
- | -- | ---------- | ------- |
258
- | 1 | John Smith | Active |
259
- | 2 | Jane Doe | Pending |
260
- MARKDOWN
261
-
262
- expect(result).to match_markdown(expected)
263
- end
264
- end
265
- end
54
+ html_table = page.find('#users-table')
55
+ expect(html_table).to match_markdown(expected_markdown)
266
56
  ```
267
57
 
268
- #### Testing HTML Table Output
269
-
270
- The `match_markdown` matcher can also compare HTML tables by extracting their semantic content:
58
+ ### Converting Between Formats
271
59
 
272
60
  ```ruby
273
- RSpec.describe HtmlReportGenerator do
274
- describe "#generate_sales_report" do
275
- it "generates the expected HTML table" do
276
- sales_data = [
277
- { product: "Widget A", quantity: 150, revenue: "$3,000" },
278
- { product: "Widget B", quantity: 75, revenue: "$1,875" }
279
- ]
280
-
281
- generator = HtmlReportGenerator.new(sales_data)
282
- html_output = generator.generate_sales_report
283
-
284
- # The matcher extracts the data structure from both the HTML and expected markdown
285
- expected = <<~MARKDOWN
286
- | Product | Quantity | Revenue |
287
- | -------- | -------- | ------- |
288
- | Widget A | 150 | $3,000 |
289
- | Widget B | 75 | $1,875 |
290
- MARKDOWN
291
-
292
- # This will pass even though one is HTML and one is Markdown!
293
- expect(html_output).to match_markdown(expected)
294
- end
295
- end
296
- end
297
- ```
61
+ # From markdown to other formats
62
+ markdown = <<~MARKDOWN
63
+ | Name | Age |
64
+ |------ | --- |
65
+ | Alice | 30 |
66
+ | Bob | 25 |
67
+ MARKDOWN
298
68
 
299
- #### Testing API JSON Responses
69
+ table = Marktable.from_markdown(markdown)
300
70
 
301
- The matcher is also helpful when testing APIs that return tabular data:
71
+ table.to_a # Array of hashes
72
+ table.to_csv # CSV string
73
+ table.to_html # HTML table
302
74
 
303
- ```ruby
304
- RSpec.describe "Products API" do
305
- describe "GET /api/products" do
306
- it "returns products in the expected format" do
307
- # Setup test data and make request
308
- get "/api/products"
309
-
310
- # Parse JSON response
311
- json_response = JSON.parse(response.body)
312
-
313
- # Convert API response to a table
314
- table = Marktable.new(json_response)
315
-
316
- expected = <<~MARKDOWN
317
- | id | name | category | price |
318
- | -- | ----------- | -------- | ------ |
319
- | 1 | Product One | Books | $19.99 |
320
- | 2 | Product Two | Games | $59.99 |
321
- MARKDOWN
322
-
323
- expect(table).to match_markdown(expected)
324
- end
325
- end
326
- end
75
+ # From arrays or hashes to markdown
76
+ data = [{ 'Name' => 'Alice', 'Age' => '30' }]
77
+ Marktable.from_array(data).to_md # Markdown table
327
78
  ```
328
79
 
329
- The `match_markdown` matcher compares tables semantically rather than character-by-character, which means:
330
-
331
- - It ignores differences in whitespace padding
332
- - It handles different column ordering in hash-based tables
333
- - It works with both HTML and Markdown table formats
334
- - It provides clear error messages showing the differences between tables
335
-
336
- ## 📋 API Reference
337
-
338
- ### Class Methods
339
-
340
- - `Marktable.parse(table, headers: nil)` - Parse table string or array into an array of hashes/arrays
341
- - `Marktable.new(table, headers: nil)` - Create a new Table object
342
- - `Marktable.parse_line(row)` - Parse a single markdown row into an array
343
- - `Marktable.generate { |t| ... }` - Generate a table with a block
344
-
345
- ### Instance Methods
346
-
347
- - `table.to_a` - Convert table to array of hashes/arrays
348
- - `table.to_s` / `table.generate` - Generate markdown representation
349
- - `table.empty?` - Check if table is empty
350
- - `table.column_count` - Get column count
351
- - `table << row_data` - Add a row to the table
352
- - `table.filter(pattern = nil) { |row| ... }` - Filter rows by pattern or block
353
- - `table.map { |row| ... }` - Transform rows with a block
354
-
355
- ## 🧪 Development
356
-
357
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
358
-
359
- To install this gem onto your local machine, run `bundle exec rake install`.
360
-
361
- ## 🤝 Contributing
362
-
363
- Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/marktable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yourusername/marktable/blob/main/CODE_OF_CONDUCT.md).
80
+ ## Documentation
364
81
 
365
- 1. Fork the repository
366
- 2. Create your feature branch: `git checkout -b my-new-feature`
367
- 3. Commit your changes: `git commit -am 'Add some feature'`
368
- 4. Push to the branch: `git push origin my-new-feature`
369
- 5. Submit a pull request
82
+ * [Full Examples](docs/examples.md) - Detailed usage examples
83
+ * [API Documentation](docs/api_documentation.md) - Complete API reference
370
84
 
371
- ## 📄 License
85
+ ## License
372
86
 
373
87
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
88
+ `
@@ -23,7 +23,7 @@ module Marktable
23
23
  doc.tbody do
24
24
  rows.each do |row|
25
25
  doc.tr do
26
- row.each_value do |cell|
26
+ row.values.each do |cell|
27
27
  doc.td do
28
28
  cell_text = cell.to_s
29
29
  if cell_text.include?('\n')
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../rspec'
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'capybara'
4
+ require 'nokogiri'
5
+ require 'marktable'
6
+
7
+ # Register the matchers if RSpec is defined
8
+ if defined?(RSpec)
9
+ RSpec::Matchers.define :match_markdown do |expected_markdown|
10
+ chain :with_format do |format|
11
+ @format = format
12
+ end
13
+
14
+ match do |actual|
15
+ @expected_data = parse_input(expected_markdown, :markdown)
16
+ @format ||= infer_format(actual)
17
+ @actual_data = parse_input(actual, @format)
18
+
19
+ # Compare data using to_a for consistent comparison
20
+ @actual_data.to_a == @expected_data.to_a
21
+ end
22
+
23
+ failure_message do
24
+ format_failure_message(@expected_data, @actual_data)
25
+ end
26
+
27
+ failure_message_when_negated do
28
+ "Expected markdown tables to differ, but they match:\n\n" \
29
+ "#{@actual_data.to_md}"
30
+ end
31
+
32
+ private
33
+
34
+ def parse_input(input, format = nil)
35
+ return input if input.is_a?(Marktable::Table)
36
+
37
+ # Handle both Capybara::Node::Element and Capybara::Node::Simple
38
+ if capybara?(input)
39
+ # Convert Capybara element to Nokogiri element or HTML
40
+ input = input.native
41
+ format = :html
42
+ end
43
+
44
+ # Handle Nokogiri elements
45
+ if nokogiri?(input)
46
+ input = input.to_html
47
+ format = :html
48
+ end
49
+
50
+ Marktable::Table.new(input, type: format)
51
+ end
52
+
53
+ def html?(data)
54
+ nokogiri?(data) || capybara?(data)
55
+ end
56
+
57
+ def capybara?(data)
58
+ defined?(Capybara::Node::Base) && data.is_a?(Capybara::Node::Base) ||
59
+ defined?(Capybara::Node::Simple) && data.is_a?(Capybara::Node::Simple) ||
60
+ defined?(Capybara::Node::Element) && data.is_a?(Capybara::Node::Element)
61
+ end
62
+
63
+ def nokogiri?(data)
64
+ defined?(Nokogiri::XML::Node) && data.is_a?(Nokogiri::XML::Node)
65
+ end
66
+
67
+ def infer_format(data)
68
+ case data
69
+ when Array
70
+ :array
71
+ when CSV::Table
72
+ :csv
73
+ when Marktable::Table
74
+ :markdown
75
+ when html?(data)
76
+ :html
77
+ else
78
+ :markdown
79
+ end
80
+ end
81
+
82
+ def format_failure_message(expected_data, actual_data)
83
+ "Expected markdown table to match:\n\n" \
84
+ "Expected:\n#{expected_data.to_md}\n\n" \
85
+ "Actual:\n#{actual_data.to_md}\n\n" \
86
+ "Parsed expected data: #{expected_data.to_a.inspect}\n" \
87
+ "Parsed actual data: #{actual_data.to_a.inspect}"
88
+ end
89
+ end
90
+ end
@@ -14,7 +14,7 @@ module Marktable
14
14
  end
15
15
 
16
16
  def parse
17
- return blank if table.nil? || rows.empty?
17
+ return Tables::Base.blank if table.nil? || rows.empty?
18
18
 
19
19
  if has_headers?
20
20
  headers = extract_row_cells(first_row)
@@ -48,7 +48,31 @@ module Marktable
48
48
  end
49
49
 
50
50
  def extract_row_cells(row)
51
- row.css('th, td').map(&:text)
51
+ row.css('th, td').map do |cell|
52
+ # Get text content
53
+ text = cell.text
54
+
55
+ # Handle JSON content specially to preserve important whitespace
56
+ if text.include?('{') && text.include?('}')
57
+ # Process JSON content more carefully
58
+ # 1. Remove newlines
59
+ # 2. Preserve spaces between JSON delimiters
60
+ # 3. Normalize other whitespace
61
+ json_content = text.gsub(/\r?\n/, ' ') # Replace newlines with spaces
62
+ .gsub(/(\{)\s*/, '\1 ') # Ensure exactly one space after opening brace
63
+ .gsub(/\s*(\})/, ' \1') # Ensure exactly one space before closing brace
64
+ .gsub(/\s+/, ' ') # Collapse other consecutive whitespace
65
+ .gsub(/\A\s+|\s+\z/, '') # Trim leading/trailing whitespace
66
+ .gsub(/\u00A0/, ' ') # Replace &nbsp; with spaces
67
+ json_content
68
+ else
69
+ # For regular content
70
+ text.gsub(/\r?\n/, '') # Remove all newlines completely
71
+ .gsub(/\s+/, ' ') # Collapse consecutive whitespace
72
+ .gsub(/\A\s+|\s+\z/, '') # Trim leading/trailing whitespace
73
+ .gsub(/\u00A0/, ' ') # Replace &nbsp; with spaces
74
+ end
75
+ end
52
76
  end
53
77
 
54
78
  def first_row
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Marktable
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/marktable.rb CHANGED
@@ -22,3 +22,5 @@ module Marktable
22
22
  Table.new(table, type: :html)
23
23
  end
24
24
  end
25
+
26
+ require_relative 'marktable/rspec' if defined?(RSpec) || defined?(::RSpec::Core)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marktable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francois Gaspard
@@ -67,6 +67,8 @@ files:
67
67
  - lib/marktable/formatters/html.rb
68
68
  - lib/marktable/formatters/markdown.rb
69
69
  - lib/marktable/row.rb
70
+ - lib/marktable/rspec.rb
71
+ - lib/marktable/rspec/init.rb
70
72
  - lib/marktable/table.rb
71
73
  - lib/marktable/tables/array.rb
72
74
  - lib/marktable/tables/base.rb
@@ -74,7 +76,6 @@ files:
74
76
  - lib/marktable/tables/html.rb
75
77
  - lib/marktable/tables/markdown.rb
76
78
  - lib/marktable/version.rb
77
- - spec/support/matchers/markdown_matchers.rb
78
79
  homepage: https://github.com/Francois-gaspard/marktable
79
80
  licenses:
80
81
  - MIT
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'capybara'
4
- require 'nokogiri'
5
-
6
- RSpec::Matchers.define :match_markdown do |expected_markdown|
7
- chain :with_format do |format|
8
- @format = format
9
- end
10
-
11
- match do |actual|
12
- @expected_data = parse_input(expected_markdown, :markdown)
13
- @format ||= infer_format(actual)
14
- @actual_data = parse_input(actual, @format)
15
-
16
- # Compare data using to_a for consistent comparison
17
- @actual_data.to_a == @expected_data.to_a
18
- end
19
-
20
- failure_message do
21
- format_failure_message(@expected_data, @actual_data)
22
- end
23
-
24
- failure_message_when_negated do
25
- "Expected markdown tables to differ, but they match:\n\n" \
26
- "#{@actual_data.to_md}"
27
- end
28
-
29
- private
30
-
31
- def parse_input(input, format = nil)
32
- return input if input.is_a?(Marktable::Table)
33
-
34
- Marktable::Table.new(input, type: format)
35
- end
36
-
37
- def infer_format(data)
38
- case data
39
- when Array
40
- :array
41
- when CSV::Table
42
- :csv
43
- when Marktable::Table
44
- :markdown
45
- else
46
- :markdown
47
- end
48
- end
49
-
50
- def format_failure_message(expected_data, actual_data)
51
- "Expected markdown table to match:\n\n" \
52
- "Expected:\n#{expected_data.to_md}\n\n" \
53
- "Actual:\n#{actual_data.to_md}\n\n" \
54
- "Parsed expected data: #{expected_data.to_a.inspect}\n" \
55
- "Parsed actual data: #{actual_data.to_a.inspect}"
56
- end
57
- end