atv 1.0.0 → 1.1.0

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: 01241ccb91e5d82a64f6ea850637960f09ae9a311cf2c246776df57e04373df5
4
- data.tar.gz: 5a04b4843e859ea00808415f876b966cd30ed4eb9330429bb2846b034e07ec1a
3
+ metadata.gz: 32b1bda3aab7e43446ace2c0667f5930b11b852f3a9fd980792e2dd81e402bd0
4
+ data.tar.gz: 85b5c46abc66065208d10c6926242505ea6ad5d17eb81aa73a4a1f9b2412eecb
5
5
  SHA512:
6
- metadata.gz: 41f03eb6c3e36e1925c7dca47652ca96d3729ffbb20854219ccd28b8a55f2b1c5c9021978ac0f2290c4492dfa927a24a43414486dd2b0f0a8046831b7b0c7d19
7
- data.tar.gz: dadd30ee857e755648608d7240ab8fd03d1333a56cdfb2b3623eabd09591d89286f7d04e05be7e230ef1b0b33043ddfb45925a534443bf9d2e3e7d73c3caa3b0
6
+ metadata.gz: 9d837481433beaa40a775ec0829ced77d0197e2032908397214fed4657d2d2134287d09f291c6e521b746fbe8cc87017072edf72aea5d6f2cef782ea77be7264
7
+ data.tar.gz: ffe91ddc9029bb1907ba8a47cec763b6406f42b30301c63e4f8f0a5085e35b9b0442e625a4520d5babcdbfa9b1754fa6b9f1358feb27cf5ea7c2445f2325e3fc
data/README.md CHANGED
@@ -27,32 +27,40 @@ or, _without_ separators, like this:
27
27
  In [Ascii Tables For Clearer Testing][1] I discuss using ascii tables to improve comprehension
28
28
  of software tests.
29
29
 
30
- [1]: https://punctuatedproductivity.wordpress.com/2016/02/02/ascii-tables-for-clearer-testing/
30
+ [1]: https://kellyfelkins.github.io/ascii-tables-for-clearer-testing/
31
31
 
32
32
  This gem was originally created when I worked at Indiegogo. Indiegogo has graciously transferred ownership of the
33
33
  gem to me so that I can maintain it going forward.
34
34
 
35
+ ## Requirements
36
+
37
+ ATV requires Ruby 3.1 or newer.
38
+
35
39
  ## Installation
36
40
 
37
41
  Add this line to your application's Gemfile:
38
42
 
39
43
  ```ruby
40
- gem 'atv'
44
+ gem "atv"
41
45
  ```
42
46
 
43
47
  And then execute:
44
48
 
45
- $ bundle
49
+ ```console
50
+ $ bundle install
51
+ ```
46
52
 
47
- Or install it yourself as:
53
+ Or install it directly:
48
54
 
49
- $ gem install atv
55
+ ```console
56
+ $ gem install atv
57
+ ```
50
58
 
51
59
  ## Usage
52
60
 
53
61
  Rows are returned or yielded as [CSV::Row][2] objects.
54
62
 
55
- [2]: http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV/Row.html
63
+ [2]: https://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV/Row.html
56
64
 
57
65
  <pre>
58
66
  |-----------------------+------------------------------+-----------------------------------|
@@ -84,15 +92,19 @@ Rows are returned or yielded as [CSV::Row][2] objects.
84
92
  **Reading a String**
85
93
 
86
94
  ```ruby
95
+ require "atv"
96
+
87
97
  atv = ATV.from_string(string)
88
98
  atv.each do |row|
89
99
  # use row here...
90
100
  end
91
101
  ```
92
102
 
93
- **Reading from am IO object**
103
+ **Reading from an IO object**
94
104
 
95
105
  ```ruby
106
+ require "atv"
107
+
96
108
  atv = ATV.new(io)
97
109
  atv.each do |row|
98
110
  # use row here...
data/lib/atv/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Atv
2
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
3
5
  end
data/lib/atv.rb CHANGED
@@ -1,15 +1,22 @@
1
- require_relative "./atv/version"
2
- require 'csv'
1
+ # frozen_string_literal: true
2
+
3
+ require "csv"
4
+ require "stringio"
5
+
6
+ require_relative "atv/version"
3
7
 
4
8
  class ATV
5
9
  include Enumerable
6
10
 
7
11
  SUBSTITUTIONS = {
8
- 'true' => true,
9
- 'false' => false,
10
- 'null' => nil,
11
- '' => nil
12
- }
12
+ "true" => true,
13
+ "false" => false,
14
+ "null" => nil,
15
+ "" => nil
16
+ }.freeze
17
+
18
+ SEPARATOR_LINE_RE = /^\s*\|\-/.freeze
19
+ COMMENT_LINE_RE = /^\s*#/.freeze
13
20
 
14
21
  attr_reader :headers
15
22
 
@@ -23,13 +30,14 @@ class ATV
23
30
  end
24
31
 
25
32
  def each
33
+ return enum_for(__method__) unless block_given?
34
+
26
35
  line_data = []
27
36
  @io.each_line do |line|
28
- next if line =~ /^\s*#/
29
- line.chomp!
30
- if (!@has_separators && !line_data.empty?) || line =~ /^\|\-/
31
- folded_items = line_data.transpose.map { |tokens| tokens.join(' ').rstrip }
32
- converted_folded_items = folded_items.map { |token| SUBSTITUTIONS.has_key?(token) ? SUBSTITUTIONS[token] : token }
37
+ next if line.match?(COMMENT_LINE_RE)
38
+ if (!@has_separators && !line_data.empty?) || line.match?(SEPARATOR_LINE_RE)
39
+ folded_items = line_data.transpose.map { |tokens| tokens.join(" ").rstrip }
40
+ converted_folded_items = folded_items.map { |token| SUBSTITUTIONS.fetch(token, token) }
33
41
  csv_row = CSV::Row.new(@headers, converted_folded_items)
34
42
  yield csv_row if csv_row.size > 0
35
43
  line_data = []
@@ -40,27 +48,28 @@ class ATV
40
48
  end
41
49
 
42
50
  def self.from_string(string)
43
- self.new(StringIO.new(string))
51
+ new(StringIO.new(string))
44
52
  end
45
53
 
46
54
  protected
47
55
 
48
56
  def split_table_line(line)
57
+ line.strip!
49
58
  return [] if line.empty?
50
- line[1..-1].split('|').map(&:strip)
59
+ line[1..].split("|").map(&:strip)
51
60
  end
52
61
 
53
62
  def has_separators?(io)
54
- @io.readline
55
- @io.readline
56
- @io.readline
63
+ 3.times { io.readline }
64
+
57
65
  separator_count = 0
58
- @io.each_line do |line|
59
- if line =~ /^\|\-/
60
- separator_count += 1
61
- return true if separator_count > 1
62
- end
66
+ io.each_line do |line|
67
+ next unless line.match?(SEPARATOR_LINE_RE)
68
+
69
+ separator_count += 1
70
+ return true if separator_count > 1
63
71
  end
72
+
64
73
  false
65
74
  end
66
75
  end
metadata CHANGED
@@ -1,78 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Felkins
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2026-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: csv
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
20
- type: :development
19
+ version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
23
+ type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '1.7'
32
+ version: '4.0'
27
33
  - !ruby/object:Gem::Dependency
28
- name: rake
34
+ name: minitest
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '5.16'
40
+ - - "<"
32
41
  - !ruby/object:Gem::Version
33
- version: '10.0'
42
+ version: '7'
34
43
  type: :development
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - "~>"
47
+ - - ">="
39
48
  - !ruby/object:Gem::Version
40
- version: '10.0'
49
+ version: '5.16'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '7'
41
53
  - !ruby/object:Gem::Dependency
42
- name: minitest
54
+ name: rake
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
45
- - - "~>"
57
+ - - ">="
46
58
  - !ruby/object:Gem::Version
47
- version: '5.11'
59
+ version: '13.0'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '14'
48
63
  type: :development
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
52
- - - "~>"
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '13.0'
70
+ - - "<"
53
71
  - !ruby/object:Gem::Version
54
- version: '5.11'
55
- description: Read data from an ascii table.
72
+ version: '14'
73
+ description: Read data from an ASCII table into CSV rows.
56
74
  email:
57
75
  - kelly@restlater.com
58
76
  executables: []
59
77
  extensions: []
60
78
  extra_rdoc_files: []
61
79
  files:
62
- - ".gitignore"
63
- - Gemfile
64
80
  - LICENSE.txt
65
81
  - README.md
66
- - Rakefile
67
- - atv.gemspec
68
82
  - lib/atv.rb
69
83
  - lib/atv/version.rb
70
- - test/atv_test.rb
71
84
  homepage: https://github.com/kellyfelkins/atv
72
85
  licenses:
73
86
  - MIT
74
- metadata: {}
75
- post_install_message:
87
+ metadata:
88
+ bug_tracker_uri: https://github.com/kellyfelkins/atv/issues
89
+ homepage_uri: https://github.com/kellyfelkins/atv
90
+ rubygems_mfa_required: 'true'
91
+ source_code_uri: https://github.com/kellyfelkins/atv
92
+ post_install_message:
76
93
  rdoc_options: []
77
94
  require_paths:
78
95
  - lib
@@ -80,17 +97,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
97
  requirements:
81
98
  - - ">="
82
99
  - !ruby/object:Gem::Version
83
- version: '0'
100
+ version: '3.1'
84
101
  required_rubygems_version: !ruby/object:Gem::Requirement
85
102
  requirements:
86
103
  - - ">="
87
104
  - !ruby/object:Gem::Version
88
105
  version: '0'
89
106
  requirements: []
90
- rubyforge_project:
91
- rubygems_version: 2.7.6
92
- signing_key:
107
+ rubygems_version: 3.4.19
108
+ signing_key:
93
109
  specification_version: 4
94
- summary: Read Ascii Table Values
95
- test_files:
96
- - test/atv_test.rb
110
+ summary: Read ASCII table values
111
+ test_files: []
data/.gitignore DELETED
@@ -1,18 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
15
- /.idea
16
- *.gem
17
- .ruby-version
18
- .ruby-gemset
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in atv.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require 'rake/testtask'
3
-
4
- Rake::TestTask.new do |t|
5
- t.libs << 'test'
6
- t.pattern = "test/*_test.rb"
7
- end
data/atv.gemspec DELETED
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'atv/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "atv"
8
- spec.version = Atv::VERSION
9
- spec.authors = ["Kelly Felkins"]
10
- spec.email = ["kelly@restlater.com"]
11
- spec.summary = "Read Ascii Table Values"
12
- spec.description = "Read data from an ascii table."
13
- spec.homepage = "https://github.com/kellyfelkins/atv"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "minitest", "~> 5.11"
24
- end
data/test/atv_test.rb DELETED
@@ -1,114 +0,0 @@
1
- require 'minitest/autorun'
2
- require_relative '../lib/atv'
3
-
4
- describe ATV do
5
- describe 'with separators' do
6
- before do
7
- @data_as_table = <<-TEXT
8
- |-----------+--------------------+--------------|
9
- | name | dob | predictable? |
10
- |-----------+--------------------+--------------|
11
- | Malcolm | September 20, 2468 | false |
12
- | Reynolds | | |
13
- |-----------+--------------------+--------------|
14
- | Zoe | February 15, 2484 | |
15
- | Washburne | | |
16
- |-----------+--------------------+--------------|
17
- | Jane | | true |
18
- |-----------+--------------------+--------------|
19
- # | Inara | October 14, 2489 | |
20
- # | Sara | | |
21
- # |-----------+--------------------+--------------|
22
- | Derrial | null | true |
23
- | Book | | |
24
- |-----------+--------------------+--------------|
25
- TEXT
26
- @expected = [
27
- ['Malcolm Reynolds', 'September 20, 2468', false],
28
- ['Zoe Washburne', 'February 15, 2484', nil],
29
- ['Jane', nil, true],
30
- ['Derrial Book', nil, true]
31
- ]
32
- end
33
-
34
- describe '#each' do
35
- before do
36
- @atv = ATV.new(StringIO.new(@data_as_table))
37
- end
38
-
39
- it 'with a block it yields rows of data as CSV rows and ignores commented lines' do
40
- i = 0
41
-
42
- @atv.each do |row|
43
- row.fields.must_equal(@expected[i])
44
- row[0].must_equal(@expected[i][0])
45
- row['name'].must_equal(@expected[i][0])
46
- row[1].must_equal(@expected[i][1])
47
- row['dob'].must_equal(@expected[i][1])
48
- row[2].must_equal(@expected[i][2])
49
- row['predictable?'].must_equal(@expected[i][2])
50
- i += 1
51
- end
52
- i.must_equal(4)
53
- end
54
-
55
- it 'without a block it returns an enumerator of data as CSV rows' do
56
- enum = @atv.enum_for
57
- enum.map(&:fields).must_equal(@expected)
58
- end
59
- end
60
-
61
- describe "#headers" do
62
- it 'returns all the headers' do
63
- ATV.new(StringIO.new(@data_as_table)).headers.must_equal(%w|name dob predictable?|)
64
- end
65
- end
66
-
67
- describe ".from_string(string)" do
68
- it 'initializes ATV with an IO object' do
69
- fussy = -> (io) { io.must_be_kind_of StringIO }
70
-
71
- ATV.stub :new, fussy do
72
- ATV.from_string(@data_as_table)
73
- end
74
- end
75
- end
76
- end
77
-
78
- describe 'without separators' do
79
- describe '#each' do
80
- it 'with a block it yields rows of data as CSV rows' do
81
- data_as_table = <<-TEXT
82
- |-----------+--------------------+--------------|
83
- | name | dob | predictable? |
84
- |-----------+--------------------+--------------|
85
- | Malcolm | September 20, 2468 | false |
86
- | Zoe | February 15, 2484 | |
87
- | Derrial | null | true |
88
- |-----------+--------------------+--------------|
89
- TEXT
90
-
91
- expected = [
92
- ['Malcolm', 'September 20, 2468', false],
93
- ['Zoe', 'February 15, 2484', nil],
94
- ['Derrial', nil, true]
95
- ]
96
- @atv = ATV.new(StringIO.new(data_as_table))
97
-
98
- i = 0
99
-
100
- @atv.each do |row|
101
- row.fields.must_equal(expected[i])
102
- row[0].must_equal(expected[i][0])
103
- row['name'].must_equal(expected[i][0])
104
- row[1].must_equal(expected[i][1])
105
- row['dob'].must_equal(expected[i][1])
106
- row[2].must_equal(expected[i][2])
107
- row['predictable?'].must_equal(expected[i][2])
108
- i += 1
109
- end
110
- i.must_equal(3)
111
- end
112
- end
113
- end
114
- end