csv_class_maker 0.1.1 → 0.2.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 +4 -4
- data/lib/csv_class_maker/csv_find.rb +13 -6
- data/spec/csv_class_maker_spec.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c337d2fc536792c333afc49688af5945e8e7892d
|
4
|
+
data.tar.gz: dc35299f89d9048ce49ffb867cedcb139e7fbd49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80c3f72db74a092de09ffcec7c361304f4a5f5ee13a18440b6f18a43109d95b7c1ad50cde9937f3c378d4381de6b114e963b8b7203a8540cfc47838a82efa8ae
|
7
|
+
data.tar.gz: fb6bb09b68875cf5cbc2c0bc763254eee695a6f905c6f129e82d4ccdee896eb5789326aa884cb694879bc52bec073bb054da2317e4f631c8cf213e6c5e8fafa5
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module CsvClassMaker::CsvFind
|
2
|
-
|
2
|
+
|
3
3
|
def all
|
4
4
|
rewind
|
5
5
|
object_array = []
|
@@ -25,9 +25,9 @@ module CsvClassMaker::CsvFind
|
|
25
25
|
if (first_line..last_line).include? line_number
|
26
26
|
row = CSV.new(`head -n 1 #{file.path} && head -n #{line_number} #{file.path} | tail -n 1`, headers: true, header_converters: :symbol, return_headers: false).first
|
27
27
|
build_instance row, line_number
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
elsif ((last_line/2+1)..last_line).include? line_number
|
29
|
+
row = CSV.new(`head -n 1 #{file.path} && tail -n #{last_line - line_number} #{file.path} | head -n 1`, headers: true, header_converters: :symbol, return_headers: false).first
|
30
|
+
build_instance row, line_number
|
31
31
|
else
|
32
32
|
nil
|
33
33
|
end
|
@@ -43,8 +43,15 @@ module CsvClassMaker::CsvFind
|
|
43
43
|
build_instance last_row, last_line
|
44
44
|
end
|
45
45
|
|
46
|
+
def each
|
47
|
+
rewind
|
48
|
+
(first_line..last_line).each do |line_number|
|
49
|
+
yield find line_number
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
46
53
|
private
|
47
|
-
|
54
|
+
|
48
55
|
def build_instance(row, line)
|
49
56
|
new_instance = self.new
|
50
57
|
row.each { |key, value| new_instance.send "#{key}=".to_sym, value }
|
@@ -82,7 +89,7 @@ module CsvClassMaker::CsvFind
|
|
82
89
|
end
|
83
90
|
end
|
84
91
|
}
|
85
|
-
|
92
|
+
|
86
93
|
@accumulator
|
87
94
|
end
|
88
95
|
|
@@ -23,7 +23,7 @@ describe Object do
|
|
23
23
|
it "responds to .first" do
|
24
24
|
(People).should respond_to(:first)
|
25
25
|
end
|
26
|
-
it ".first returns correctly" do
|
26
|
+
it ".first returns correctly" do
|
27
27
|
expect(People.first).to eq @person1
|
28
28
|
end
|
29
29
|
it "responds to .last" do
|
@@ -43,7 +43,7 @@ describe Object do
|
|
43
43
|
end
|
44
44
|
it ".find_by returns correctly" do
|
45
45
|
expect(People.find_by(nickname: 'Pebbles')).to eq @person3
|
46
|
-
expect(People.find_by(nickname: 'Pebbles', last: 'Smith')).to eq @person2
|
46
|
+
expect(People.find_by(nickname: 'Pebbles', last: 'Smith')).to eq @person2
|
47
47
|
end
|
48
48
|
it "responds to .find_all_by" do
|
49
49
|
(People).should respond_to(:find_all_by)
|
@@ -52,6 +52,14 @@ describe Object do
|
|
52
52
|
expect(People.find_all_by(nickname: 'Pebbles')).to eq [@person2, @person3]
|
53
53
|
expect(People.find_all_by(nickname: 'Pebbles', last: 'Radiation')).to eq [@person3]
|
54
54
|
end
|
55
|
+
it "responds to .each" do
|
56
|
+
(People).should respond_to(:each)
|
57
|
+
end
|
58
|
+
it ".each line yields" do
|
59
|
+
@output = []
|
60
|
+
People.each{|person| @output << person.first}
|
61
|
+
expect(@output).to eq ['Mark', 'Longinus', 'Johnny', 'Charlie']
|
62
|
+
end
|
55
63
|
end
|
56
64
|
context 'instance methods' do
|
57
65
|
it "responds to .first as defined in the csv" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_class_maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Platt
|
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
57
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.2.
|
58
|
+
rubygems_version: 2.2.2
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
61
|
summary: "'Object oriented CSV reading'"
|