csv_filter 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = csv_filter
2
2
 
3
- Filters CSV or TSV files (default) by column names and optionally by a match on any field in rows.
3
+ Filters CSV or TSV files (default) by column names.
4
4
 
5
5
  == Contributing to csv_filter
6
6
 
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "csv_filter"
18
18
  gem.homepage = "http://github.com/kris-luminar/csv_filter"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{filters csv/tsv files by column and (optionally) row}
21
- gem.description = %Q{Filters CSV or TSV files (default) by column names and optionally by a match on any field in rows.}
20
+ gem.summary = %Q{filters csv/tsv files by column name}
21
+ gem.description = %Q{Filters CSV or TSV files (default) by column names}
22
22
  gem.email = "kris.luminar@gmail.com"
23
23
  gem.authors = ["Kris Luminar"]
24
24
  # dependencies defined in Gemfile
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
data/bin/csv_filter CHANGED
@@ -1,4 +1,4 @@
1
- #!/Users/krisluminar/.rbenv/shims/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require 'csv_filter'
4
4
 
@@ -7,6 +7,7 @@ cf = CsvFilter.new(file_path)
7
7
 
8
8
  puts "available fields are: #{cf.fields}"
9
9
  puts "enter field names to filter"
10
- fields = gets.chomp
11
- cf.print_filter(fields.split(' '))
12
- puts "help"
10
+ fields = gets.chomp.split(/\s/)
11
+ cf.print_filter(fields)
12
+
13
+ exit 0
data/csv_filter.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "csv_filter"
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
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
12
  s.date = "2012-12-11"
13
- s.description = "Filters CSV or TSV files (default) by column names and optionally by a match on any field in rows."
13
+ s.description = "Filters CSV or TSV files (default) by column names"
14
14
  s.email = "kris.luminar@gmail.com"
15
15
  s.executables = ["csv_filter"]
16
16
  s.extra_rdoc_files = [
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.licenses = ["MIT"]
41
41
  s.require_paths = ["lib"]
42
42
  s.rubygems_version = "1.8.23"
43
- s.summary = "filters csv/tsv files by column and (optionally) row"
43
+ s.summary = "filters csv/tsv files by column name"
44
44
 
45
45
  if s.respond_to? :specification_version then
46
46
  s.specification_version = 3
data/lib/csv_filter.rb CHANGED
@@ -3,7 +3,6 @@ class CsvFilter
3
3
  # @param file_path the full path to a file
4
4
  def initialize file_path, separator = "\t"
5
5
  STDOUT.flush
6
- puts "point 1"
7
6
  @file = File.open(file_path, 'r')
8
7
  @separator = separator
9
8
  @num_columns = count_columns
@@ -30,7 +29,6 @@ class CsvFilter
30
29
  end
31
30
 
32
31
  def filter(*columns)
33
- puts "point 3"
34
32
  # columns = [*columns].flatten #columns should accept either an array of strings or a variable number of strings
35
33
  raise ArgumentError unless (columns.respond_to?(:size) and columns.size < @num_columns)
36
34
  output = []
@@ -38,30 +36,27 @@ class CsvFilter
38
36
  #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.
39
37
  next if i == 0 # skip header row
40
38
  row = {}
41
- line.split(@separator).each_with_index do |value, j|
39
+ line.chomp.split(@separator).each_with_index do |value, j|
42
40
  if filtered_column_positions(columns).include? j
43
41
  row[@header[j]] = value
44
42
  end
45
- output << row
46
43
  end
44
+ output << row
47
45
  end
48
46
  output
49
47
  end
50
48
 
51
49
  def print_filter(columns)
52
- STDOUT.flush
53
- puts "point 2"
54
- STDOUT.flush
55
50
  lines = filter(columns)
56
51
  output = []
57
52
  lines.each_with_index do |line, i|
58
- row = "#{i}. "
53
+ row = "#{i}.".ljust(6)
59
54
  line.each do |k,v|
60
55
  row << "#{v}\t"
61
56
  end
62
57
  output << row
63
58
  end
64
- print output.join("\n")
59
+ puts output.join("\n")
65
60
  end
66
61
 
67
62
  def count_columns
@@ -41,16 +41,10 @@ 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 raising an exception
44
+ #exit code and puts warning rather than raising an exception
45
+ it "should return a warning if all args not in header line"
45
46
 
46
- it "should grep for a string in rows"
47
47
  describe "console output"
48
48
  it "should send output to stndout"
49
49
  it "should return just the columns specified"
50
- describe "to_file"
51
- it "should create the named file"
52
- it "should send success message to stdout"
53
- it "should not send the file contents to stdout"
54
- describe "file contents"
55
- it "should include just the columns specified"
56
50
  end
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.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -91,8 +91,7 @@ dependencies:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
93
  version: 1.8.4
94
- description: Filters CSV or TSV files (default) by column names and optionally by
95
- a match on any field in rows.
94
+ description: Filters CSV or TSV files (default) by column names
96
95
  email: kris.luminar@gmail.com
97
96
  executables:
98
97
  - csv_filter
@@ -133,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
132
  version: '0'
134
133
  segments:
135
134
  - 0
136
- hash: -2098023392159934889
135
+ hash: 4030006348523475583
137
136
  required_rubygems_version: !ruby/object:Gem::Requirement
138
137
  none: false
139
138
  requirements:
@@ -145,5 +144,5 @@ rubyforge_project:
145
144
  rubygems_version: 1.8.23
146
145
  signing_key:
147
146
  specification_version: 3
148
- summary: filters csv/tsv files by column and (optionally) row
147
+ summary: filters csv/tsv files by column name
149
148
  test_files: []