csv_filter 0.2.0 → 0.2.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/bin/csv_filter ADDED
@@ -0,0 +1,12 @@
1
+ #!/Users/krisluminar/.rbenv/shims/ruby
2
+
3
+ require 'csv_filter'
4
+
5
+ file_path = File.expand_path(ARGV.unshift.pop)
6
+ cf = CsvFilter.new(file_path)
7
+
8
+ puts "available fields are: #{cf.fields}"
9
+ puts "enter field names to filter"
10
+ fields = gets.chomp
11
+ cf.print_filter(fields.split(' '))
12
+ puts "help"
data/csv_filter.gemspec CHANGED
@@ -5,13 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "csv_filter"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kris Luminar"]
12
- s.date = "2012-12-10"
12
+ s.date = "2012-12-11"
13
13
  s.description = "Filters CSV or TSV files (default) by column names and optionally by a match on any field in rows."
14
14
  s.email = "kris.luminar@gmail.com"
15
+ s.executables = ["csv_filter"]
15
16
  s.extra_rdoc_files = [
16
17
  "LICENSE.txt",
17
18
  "README.rdoc"
@@ -28,6 +29,7 @@ Gem::Specification.new do |s|
28
29
  "README.rdoc",
29
30
  "Rakefile",
30
31
  "VERSION",
32
+ "bin/csv_filter",
31
33
  "csv_filter.gemspec",
32
34
  "lib/csv_filter.rb",
33
35
  "spec/csv_filter_spec.rb",
data/lib/csv_filter.rb CHANGED
@@ -2,6 +2,8 @@
2
2
  class CsvFilter
3
3
  # @param file_path the full path to a file
4
4
  def initialize file_path, separator = "\t"
5
+ STDOUT.flush
6
+ puts "point 1"
5
7
  @file = File.open(file_path, 'r')
6
8
  @separator = separator
7
9
  @num_columns = count_columns
@@ -28,11 +30,12 @@ class CsvFilter
28
30
  end
29
31
 
30
32
  def filter(*columns)
31
- # columns = [*columns] #columns should accept either an array of strings or a variable number of strings
33
+ puts "point 3"
34
+ # columns = [*columns].flatten #columns should accept either an array of strings or a variable number of strings
32
35
  raise ArgumentError unless (columns.respond_to?(:size) and columns.size < @num_columns)
33
36
  output = []
34
37
  @file.each_with_index do |line, i|
35
- #TODO: Decide whether to allow user to specify if header row exists. If so, this step will be conditional. Else, add proviso to the README that csv file must include a header line.
38
+ #TODO: Decide wther to allow user to specify if header row exists. If so, this step will be conditional. Else, add proviso to the README that csv file must include a header line.
36
39
  next if i == 0 # skip header row
37
40
  row = {}
38
41
  line.split(@separator).each_with_index do |value, j|
@@ -45,6 +48,22 @@ class CsvFilter
45
48
  output
46
49
  end
47
50
 
51
+ def print_filter(columns)
52
+ STDOUT.flush
53
+ puts "point 2"
54
+ STDOUT.flush
55
+ lines = filter(columns)
56
+ output = []
57
+ lines.each_with_index do |line, i|
58
+ row = "#{i}. "
59
+ line.each do |k,v|
60
+ row << "#{v}\t"
61
+ end
62
+ output << row
63
+ end
64
+ print output.join("\n")
65
+ end
66
+
48
67
  def count_columns
49
68
  fields.size
50
69
  end
@@ -41,7 +41,7 @@ describe "CsvFilter" do
41
41
  register['url'].should eq 2
42
42
  end
43
43
 
44
- it "should return a warning if all args not in header line" #exit code and puts warning rather than exception
44
+ it "should return a warning if all args not in header line" #exit code and puts warning rather than raising an exception
45
45
 
46
46
  it "should grep for a string in rows"
47
47
  describe "console output"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-10 00:00:00.000000000 Z
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -94,7 +94,8 @@ dependencies:
94
94
  description: Filters CSV or TSV files (default) by column names and optionally by
95
95
  a match on any field in rows.
96
96
  email: kris.luminar@gmail.com
97
- executables: []
97
+ executables:
98
+ - csv_filter
98
99
  extensions: []
99
100
  extra_rdoc_files:
100
101
  - LICENSE.txt
@@ -111,6 +112,7 @@ files:
111
112
  - README.rdoc
112
113
  - Rakefile
113
114
  - VERSION
115
+ - bin/csv_filter
114
116
  - csv_filter.gemspec
115
117
  - lib/csv_filter.rb
116
118
  - spec/csv_filter_spec.rb
@@ -131,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
133
  version: '0'
132
134
  segments:
133
135
  - 0
134
- hash: -429245302767386299
136
+ hash: -2098023392159934889
135
137
  required_rubygems_version: !ruby/object:Gem::Requirement
136
138
  none: false
137
139
  requirements: