scsv 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ === 0.1.0 2010-01-23
2
+
3
+ * first release
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/scsv.rb
7
+ script/console
8
+ script/console.cmd
9
+ script/destroy
10
+ script/destroy.cmd
11
+ script/generate
12
+ script/generate.cmd
13
+ spec/scsv_spec.rb
14
+ spec/spec.opts
15
+ spec/spec_helper.rb
16
+ tasks/rspec.rake
@@ -0,0 +1,7 @@
1
+
2
+ For more information on scsv, see http://scsv.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,56 @@
1
+ = scsv
2
+
3
+ * http://github.com/kinumi/scsv
4
+
5
+ == DESCRIPTION:
6
+
7
+ A simple CSV(and TSV) parser to convert line into the Hash using header info.
8
+
9
+ == SYNOPSIS:
10
+
11
+ require "scsv"
12
+
13
+ #
14
+ # a.csv
15
+ # -----------
16
+ # h1,h2,h3
17
+ # d1,d2,d3
18
+ # d4,d5,d6
19
+ #
20
+
21
+ SCSV.parse("a.csv") do |line|
22
+ p line
23
+ end
24
+ #=> {"h1" => "d1", "h2" => "d2", "h3" => "d3"}
25
+ #=> {"h1" => "d4", "h2" => "d5", "h3" => "d6"}
26
+ p SCSV.parse("a.csv")
27
+ #=> [{"h1" => "d1", "h2" => "d2", "h3" => "d3"}, {"h1" => "d4", "h2" => "d5", "h3" => "d6"}]
28
+
29
+ == INSTALL:
30
+
31
+ gem install scsv
32
+
33
+ == LICENSE:
34
+
35
+ (The MIT License)
36
+
37
+ Copyright (c) 2010 kinumi
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining
40
+ a copy of this software and associated documentation files (the
41
+ 'Software'), to deal in the Software without restriction, including
42
+ without limitation the rights to use, copy, modify, merge, publish,
43
+ distribute, sublicense, and/or sell copies of the Software, and to
44
+ permit persons to whom the Software is furnished to do so, subject to
45
+ the following conditions:
46
+
47
+ The above copyright notice and this permission notice shall be
48
+ included in all copies or substantial portions of the Software.
49
+
50
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
51
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
52
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
53
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
54
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
55
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
56
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/scsv'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'scsv' do
14
+ self.developer 'kinumi', 'kunimi.ikeda@gmail.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
@@ -0,0 +1,66 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ #
5
+ # for COMMA separated file
6
+ #
7
+ class SCSV
8
+ VERSION = '0.1.0'
9
+
10
+ DEFAULT_OPTIONS = {
11
+ :col_sep => ",",
12
+ :row_sep => "\n",
13
+ :header => true,
14
+ }
15
+
16
+ def self.parse(filename, options = {}, &block)
17
+ p options = DEFAULT_OPTIONS.merge(options)
18
+ if block_given?
19
+ parse_with_block(filename, options, &block)
20
+ else
21
+ rows = []
22
+ parse_with_block(filename, options) do |row|
23
+ rows << row
24
+ end
25
+ return rows
26
+ end
27
+ end
28
+
29
+ def self.parse_with_block(filename, options, &block)
30
+ Kernel.open(filename, "r") do |f|
31
+ header = nil
32
+ if options[:header] && options[:header].is_a?(Array)
33
+ # using passed Array
34
+ header = options[:header]
35
+ elsif options[:header]
36
+ # using file's first row
37
+ header = f.gets.gsub(/\n/, "").split(options[:col_sep])
38
+ end
39
+ # read lines
40
+ f.each do |line|
41
+ tokens = line.gsub(/\n/, "").split(options[:col_sep])
42
+ row = tokens
43
+ if header
44
+ row = {}
45
+ tokens.each_with_index do |i, idx|
46
+ row[header[idx]] = i
47
+ end
48
+ end
49
+ yield(row)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ #
56
+ # for TAB separated file
57
+ #
58
+ class STSV < SCSV
59
+ # overwrite col_sep
60
+ DEFAULT_OPTIONS = DEFAULT_OPTIONS.dup
61
+ DEFAULT_OPTIONS[:col_sep] = "\t"
62
+ # overwrite methods
63
+ def self.parse(filename, options = DEFAULT_OPTIONS, &block)
64
+ super
65
+ end
66
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/scsv.rb'}"
9
+ puts "Loading scsv gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1 @@
1
+ @ruby script/console %*
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1 @@
1
+ @ruby script/destroy %*
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1 @@
1
+ @ruby script/generate %*
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ # violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'scsv'
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scsv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kinumi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-23 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubyforge
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: gemcutter
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.5.0
44
+ version:
45
+ description: A simple CSV(and TSV) parser to convert line into the Hash using header info.
46
+ email:
47
+ - kunimi.ikeda@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - PostInstall.txt
56
+ files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ - PostInstall.txt
60
+ - README.rdoc
61
+ - Rakefile
62
+ - lib/scsv.rb
63
+ - script/console
64
+ - script/console.cmd
65
+ - script/destroy
66
+ - script/destroy.cmd
67
+ - script/generate
68
+ - script/generate.cmd
69
+ - spec/scsv_spec.rb
70
+ - spec/spec.opts
71
+ - spec/spec_helper.rb
72
+ - tasks/rspec.rake
73
+ has_rdoc: true
74
+ homepage: http://github.com/kinumi/scsv
75
+ licenses: []
76
+
77
+ post_install_message: PostInstall.txt
78
+ rdoc_options:
79
+ - --main
80
+ - README.rdoc
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project: scsv
98
+ rubygems_version: 1.3.5
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: A simple CSV(and TSV) parser to convert line into the Hash using header info.
102
+ test_files: []
103
+