csv_class_maker 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/csv_class_maker.rb +3 -1
- data/lib/csv_class_maker/csv_class_maker.rb +6 -5
- data/spec/csv_class_maker_spec.rb +11 -101
- metadata +22 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fbae6e1e7d3b23562a1a7043032a73c4bad1a544ddfa2e9250bf30c89e9d26d4
|
4
|
+
data.tar.gz: fefe1ecffb86806c7c9cb35babb2791e1eb7feab8c056bc9f30eb66b60ac31fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f08d07ecfe0a3e0d1be32952b65b6343f55716a9ddf60b3c326b9f241e6c4f69002645f7e354f65bb783d5503052d4644457a7b41bdb8d45dceeea0328159811
|
7
|
+
data.tar.gz: 88d33c001a09dba60689f760267a9b61fbae11fd9a3018edef82ab8e3d91cec5e60595818c026047835e9b4f0e7c770f05a79d7fd06dce1f1904f41a3c38f9bd
|
data/lib/csv_class_maker.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Usage:
|
2
4
|
#
|
3
5
|
# require './csv_class_maker'
|
4
6
|
# CsvClassMaker::generate_class 'Batting', '/Users/mplatt/Desktop/Batting.csv'
|
5
7
|
|
6
|
-
module CsvClassMaker
|
8
|
+
module CsvClassMaker #:nodoc:
|
7
9
|
require 'csv'
|
8
10
|
|
9
11
|
VERSION = {
|
10
|
-
major: '
|
11
|
-
minor: '
|
12
|
+
major: '2',
|
13
|
+
minor: '0',
|
12
14
|
patch: '0'
|
13
15
|
}.values.join('.')
|
14
16
|
|
@@ -16,7 +18,6 @@ module CsvClassMaker
|
|
16
18
|
Object.const_set(class_name, Class.new do
|
17
19
|
include CsvFind
|
18
20
|
csv_file(file_name, options)
|
19
|
-
end
|
20
|
-
)
|
21
|
+
end)
|
21
22
|
end
|
22
23
|
end
|
@@ -1,114 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require './lib/csv_class_maker'
|
2
4
|
|
3
5
|
describe CsvClassMaker do
|
4
6
|
context 'class methods' do
|
5
7
|
describe 'generate_class' do
|
6
8
|
it 'makes a new class object from a file' do
|
7
|
-
CsvClassMaker
|
8
|
-
Object.constants.include
|
9
|
+
CsvClassMaker.generate_class 'People', 'spec/support/demo.csv'
|
10
|
+
expect(Object.constants).to include(:People)
|
9
11
|
end
|
10
12
|
|
11
13
|
it 'takes a file options' do
|
12
|
-
people = CsvClassMaker
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
describe Object do
|
20
|
-
before(:all){
|
21
|
-
@person1 = People.new(first: 'Mark', last: 'Platt', nickname: 'JCool', line_number: 2)
|
22
|
-
@person2 = People.new(first: 'Longinus', last: 'Smith', nickname: 'Pebbles', line_number: 3)
|
23
|
-
@person3 = People.new(first: 'Johnny', last: 'Radiation', nickname: 'Pebbles', line_number: 4)
|
24
|
-
@person4 = People.new(first: 'Charlie', last: 'Mansfield', nickname: 'Sammykins', line_number: 5)
|
25
|
-
}
|
26
|
-
|
27
|
-
context 'class methods' do
|
28
|
-
it "responds to .first" do
|
29
|
-
(People).should respond_to(:first)
|
30
|
-
end
|
31
|
-
|
32
|
-
it ".first returns correctly" do
|
33
|
-
expect(People.first).to eq @person1
|
34
|
-
end
|
35
|
-
|
36
|
-
it "responds to .last" do
|
37
|
-
(People).should respond_to(:last)
|
38
|
-
end
|
39
|
-
|
40
|
-
it ".last returns correctly" do
|
41
|
-
expect(People.last).to eq @person4
|
42
|
-
end
|
43
|
-
|
44
|
-
it "responds to .find" do
|
45
|
-
(People).should respond_to(:find)
|
46
|
-
end
|
47
|
-
|
48
|
-
it ".find returns correctly" do
|
49
|
-
expect(People.find(2)).to eq @person1
|
50
|
-
expect(People.find(3)).to eq @person2
|
51
|
-
expect(People.find(4)).to eq @person3
|
52
|
-
expect(People.find(5)).to eq @person4
|
53
|
-
end
|
54
|
-
|
55
|
-
it "[DEPRECATED] responds to .find_by" do
|
56
|
-
(People).should respond_to(:find_by)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "[DEPRECATED] .find_by returns correctly" do
|
60
|
-
expect(People.find_by(nickname: 'Pebbles')).to eq @person3
|
61
|
-
expect(People.find_by(nickname: 'Pebbles', last: 'Smith')).to eq @person2
|
62
|
-
end
|
14
|
+
people = CsvClassMaker.generate_class(
|
15
|
+
'Other',
|
16
|
+
'spec/support/delimeter.csv',
|
17
|
+
col_sep: "\t"
|
18
|
+
)
|
63
19
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
|
-
it "responds to .where" do
|
70
|
-
(People).should respond_to(:where)
|
71
|
-
end
|
72
|
-
|
73
|
-
it ".where returns correctly" do
|
74
|
-
expect(People.where(nickname: 'Pebbles')).to eq [@person2, @person3]
|
75
|
-
expect(People.where(nickname: 'Pebbles', last: 'Radiation')).to eq [@person3]
|
76
|
-
end
|
77
|
-
|
78
|
-
it ".where returns an empty array if there are no results" do
|
79
|
-
expect(People.where(nickname: 'Beastmode')).to eq []
|
80
|
-
end
|
81
|
-
|
82
|
-
it "[DEPRECATED] responds to .find_all_by" do
|
83
|
-
(People).should respond_to(:find_all_by)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "[DEPRECATED] .find_all_by returns correctly" do
|
87
|
-
expect(People.find_all_by(nickname: 'Pebbles')).to eq [@person2, @person3]
|
88
|
-
expect(People.find_all_by(nickname: 'Pebbles', last: 'Radiation')).to eq [@person3]
|
89
|
-
end
|
90
|
-
|
91
|
-
it "responds to .each" do
|
92
|
-
(People).should respond_to(:each)
|
93
|
-
end
|
94
|
-
|
95
|
-
it ".each line yields" do
|
96
|
-
@output = []
|
97
|
-
People.each{ |person| @output << person.first }
|
98
|
-
expect(@output).to eq ['Mark', 'Longinus', 'Johnny', 'Charlie']
|
99
|
-
end
|
100
|
-
end
|
101
|
-
context 'instance methods' do
|
102
|
-
it "responds to .first as defined in the csv" do
|
103
|
-
(People.new).should respond_to(:first)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "responds to .last as defined in the csv" do
|
107
|
-
(People.new).should respond_to(:last)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "responds to .nickname as defined in the csv" do
|
111
|
-
(People.new).should respond_to(:nickname)
|
20
|
+
expect(people.first).to respond_to(:nickname)
|
21
|
+
end
|
112
22
|
end
|
113
23
|
end
|
114
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_class_maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Platt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: csv_find
|
@@ -16,28 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0
|
19
|
+
version: 1.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0
|
26
|
+
version: 1.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.9.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.82'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.82'
|
41
55
|
description: "'csv_class_maker will create a class out of your csv's headers, and
|
42
56
|
provide some methods for finding data in the CSV'"
|
43
57
|
email: mplatt@mrkplt.com
|
@@ -60,15 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
74
|
requirements:
|
61
75
|
- - ">="
|
62
76
|
- !ruby/object:Gem::Version
|
63
|
-
version: 2.
|
77
|
+
version: 2.5.0
|
64
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
requirements: []
|
70
|
-
|
71
|
-
rubygems_version: 2.2.2
|
84
|
+
rubygems_version: 3.1.2
|
72
85
|
signing_key:
|
73
86
|
specification_version: 4
|
74
87
|
summary: "'Object oriented CSV reading'"
|