cosvon 0.0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dfe2240d43b01ac288d579f88b776459e29d7f60
4
+ data.tar.gz: 700563855505d0e54d4ba235713b2706450e7e2b
5
+ SHA512:
6
+ metadata.gz: ac440d9c893f727f677bcd6588940ff4c5f0aec636e43d31d8431749e23faf459f55bde91a73f2aaae5c6bdb4d731e978ff540bebebe62a1f0afea67c7e8905f
7
+ data.tar.gz: 9e75777edb5a7546fb88356a4205e2f9993c5647eca200617578e3a511e7e62edb312b6a74af075570e6a7e59b6de09fd66c7a842bd26a3afc8ab127deedd239
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ .DS_Store
2
+
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system 2.1.11
4
+ - gem --version
5
+ rvm:
6
+ - 1.8.7
7
+ - ree
8
+ - 1.9.2
9
+ - 1.9.3
10
+ - 2.0.0
11
+ - 2.1.0
12
+ - 2.1.1
13
+ - 2.1.2
14
+ - ruby-head
15
+ - jruby-18mode
16
+ - jruby-19mode
17
+ - jruby-20mode
18
+ - jruby-21mode
19
+ - jruby-head
20
+ - rbx-2.1.1
21
+ - rbx-2.2.3
22
+ matrix:
23
+ allow_failures:
24
+ - rvm: ruby-head
25
+ - rvm: jruby-head
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # ChangeLog
2
+
3
+ # 0.0.0.2 (20150621)
4
+ Some CSVs are broken due to SJIS dame-moji.
5
+ I have added a workaround into CoSVON.csv().
6
+
7
+ # 0.0.0.1 (20141007)
8
+ Initial version, which is blank intentionally.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+
3
+ platforms :rbx do
4
+ gem 'rubysl'
5
+ end
6
+
7
+ group :development, :test do
8
+ if RUBY_VERSION<'1.9'
9
+ gem 'mime-types', '~> 1.0'
10
+ gem 'rest-client', '~> 1.6.0'
11
+ end
12
+ gem 'bundler', '>= 1.0'
13
+ gem 'rake'
14
+ gem 'rspec'
15
+ gem 'simplecov'
16
+ gem 'coveralls', :require => false
17
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1 @@
1
+ blank intentionally
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # cosvon
2
+
3
+ Comma Separated Value Object Notation (yokohamarb)
4
+
5
+ http://nabetani.sakura.ne.jp/yokohamarb/2014.01.cosvon/
6
+
7
+ [![Build Status](https://travis-ci.org/cielavenir/cosvon.png)](https://travis-ci.org/cielavenir/cosvon) [![Code Climate](https://codeclimate.com/github/cielavenir/cosvon.png)](https://codeclimate.com/github/cielavenir/cosvon) [![Coverage Status](https://coveralls.io/repos/cielavenir/cosvon/badge.png)](https://coveralls.io/r/cielavenir/cosvon)
8
+
9
+ Notice: you must not publish this repository directly to rubygems.
10
+
11
+ Other usages are welcomed. For example, CoSVON::csv should be useful.
12
+
13
+ ## Supported Ruby versions
14
+ * Ruby 1.8.7 or later
15
+ * jruby
16
+ * rubinius 2.1.1 or 2.2.3 (or later, maybe)
17
+ * 2.2.1 and 2.2.2 are not working.
18
+ * (Possibly) ironruby / macruby / topaz etc
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'bundler/gem_tasks'
2
+ require './lib/cosvon'
3
+
4
+ ### below are copied from jeweler ###
5
+
6
+ require 'rake'
7
+ # Clean up after gem building
8
+ require 'rake/clean'
9
+ CLEAN.include('pkg/*.gem')
10
+ CLOBBER.include('coverage')
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+ RSpec::Core::RakeTask.new(:spec) do |spec|
15
+ spec.pattern = FileList['spec/**/*_spec.rb']
16
+ end
17
+
18
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
19
+ spec.pattern = 'spec/**/*_spec.rb'
20
+ spec.rcov = true
21
+ end
22
+
23
+ task :default => :spec
24
+
25
+ begin
26
+ require 'rdoc/task'
27
+ Rake::RDocTask.new do |rdoc|
28
+ rdoc.rdoc_dir = 'rdoc'
29
+ rdoc.title = 'cosvon '+CoSVON::VERSION
30
+ rdoc.main = 'README.md'
31
+ rdoc.rdoc_files.include('README.*')
32
+ rdoc.rdoc_files.include('LICENSE.*')
33
+ rdoc.rdoc_files.include('CHANGELOG.*')
34
+ rdoc.rdoc_files.include('lib/**/*.rb')
35
+ end
36
+ rescue Exception #LoadError # Thus rdoc generation is limited to Ruby 1.9.3+...
37
+ #Ruby 1.9.2 gives another Exception. I cannot limit to LoadError...
38
+ end
data/cosvon.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ require './lib/cosvon'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "cosvon"
6
+ spec.version = CoSVON::VERSION
7
+ spec.authors = ["cielavenir"]
8
+ spec.email = ["cielartisan@gmail.com"]
9
+ spec.description = "Comma Separated Value Object Notation"
10
+ spec.summary = "Comma Separated Value Object Notation"
11
+ spec.homepage = "http://github.com/cielavenir/cosvon"
12
+ spec.license = "Ruby License (2-clause BSDL or Artistic)"
13
+
14
+ spec.files = `git ls-files`.split($/) + [
15
+ "LICENSE.txt",
16
+ "README.md",
17
+ "CHANGELOG.md",
18
+ ]
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", ">= 1.0"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
data/lib/cosvon.rb ADDED
@@ -0,0 +1,101 @@
1
+ #coding:utf-8
2
+
3
+ # CoSVON: Comma Separated Value Object Notation (yokohamarb)
4
+ #
5
+ # http://nabetani.sakura.ne.jp/yokohamarb/2014.01.cosvon/
6
+
7
+ class CoSVON
8
+ HSALSKCAB='―ソЫ噂浬欺圭構蚕十申曾箪貼能表暴予禄兔喀媾彌拿杤歃濬畚秉綵臀藹觸軆鐔饅鷭偆砡'
9
+
10
+ # VERSION string
11
+ VERSION='0.0.0.2'
12
+
13
+ # parses csv string into 2D array. quoted commas/LFs and escaped quotations are supported.
14
+ def self.csv(s,__opt=Hash.new)
15
+ opt={:col_sep=>',',:quote_char=>'"'}.merge(__opt)
16
+ csv=[]
17
+ line=[]
18
+ quoted=false
19
+ quote=false
20
+ backslash=0
21
+ cur=''
22
+ (s+(s.end_with?("\n") ? "" : "\n")).each_char{|c|
23
+ if c=="\r" #ignore CR
24
+ elsif c==opt[:quote_char]
25
+ if !quoted #start of quote
26
+ quoted=true
27
+ elsif !quote #end of quote? Let's determine using next char
28
+ quote=true
29
+ if backslash==1
30
+ backslash=2
31
+ end
32
+ else #escape rather than end of quote
33
+ quote=false
34
+ cur<<opt[:quote_char]
35
+ if backslash==2
36
+ backslash=0
37
+ end
38
+ end
39
+ else
40
+ if quote
41
+ quote=false
42
+ if backslash==2
43
+ cur<<opt[:quote_char]
44
+ else
45
+ quoted=false
46
+ end
47
+ end
48
+ if c=="\n"&&!quoted
49
+ line<<cur
50
+ cur=''
51
+ csv<<line
52
+ line=[]
53
+ elsif c==opt[:col_sep]&&!quoted
54
+ line<<cur
55
+ cur=''
56
+ else
57
+ backslash=0
58
+ if HSALSKCAB.include?(c)
59
+ backslash=1
60
+ end
61
+ quote=false
62
+ cur<<c
63
+ end
64
+ end
65
+ }
66
+ csv
67
+ end
68
+
69
+ # parses CoSVON string into Hash.
70
+ # parser can be CoSVON.method(:csv), CSV.method(:parse), etc...
71
+ def self.parse(s,parser=self.method(:csv))
72
+ csv=parser[s]
73
+ return nil if csv.empty?||csv[0].empty?||csv[0][0]!='CoSVON:0.1'
74
+ csv.shift
75
+ h={}
76
+ csv.each{|e|
77
+ h[e[0]]=e[1] if e.size>1&&e[0]&&!e[0].empty?&&e[1]&&!e[1].empty?
78
+ }
79
+ h
80
+ end
81
+ # parses CoSVON file into Hash.
82
+ def self.load(path,parser=self.method(:csv))
83
+ self.parse(File.read(path),parser)
84
+ end
85
+ # generates CoSVON string from Hash.
86
+ def self.generate(h)
87
+ s="CoSVON:0.1\n"
88
+ h.each{|k,v|
89
+ s+=%Q("#{k.gsub('"','""')}","#{v.gsub('"','""')}"\n)
90
+ }
91
+ s
92
+ end
93
+ # kind-of-alias of self.generate
94
+ def self.stringify(h)
95
+ self.generate(h)
96
+ end
97
+ # generates CoSVON file from Hash.
98
+ def self.save(h,path)
99
+ File.write(path,generate(h))
100
+ end
101
+ end
@@ -0,0 +1,136 @@
1
+ SPEC_DIR=File.expand_path(File.dirname(__FILE__))
2
+ require SPEC_DIR+'/spec_helper'
3
+
4
+ cases=[
5
+ [
6
+ {
7
+ "DreamCast"=>"SEGA",
8
+ "HI-Saturn"=>"Hitachi",
9
+ "FamiconTV"=>"Sharp",
10
+ },<<-EOM
11
+ CoSVON:0.1
12
+ DreamCast,SEGA
13
+ HI-Saturn,Hitachi
14
+ FamiconTV,Sharp
15
+ EOM
16
+ ],[
17
+ {
18
+ "foo"=>"bar",
19
+ },<<-EOM
20
+ CoSVON:0.1
21
+ foo,bar
22
+ EOM
23
+ ],[
24
+ {
25
+ "comma"=>"[,]",
26
+ "dq"=>'["]',
27
+ "n"=>"[\n]",
28
+ "tab"=>"[\t]",
29
+ },<<-EOM
30
+ CoSVON:0.1
31
+ comma,"[,]"
32
+ dq,"[""]"
33
+ n,"[
34
+ ]"
35
+ tab,[ ]
36
+ EOM
37
+ ],[
38
+ {
39
+ "SH3"=>"Super Hitachi 3",
40
+ "ATOK"=>"Awa TOKushima",
41
+ "ICU" => "Isolated Crazy Utopia",
42
+ "BING"=>"Bing Is Not Google",
43
+ },<<-EOM
44
+ CoSVON:0.1
45
+ SH3,Super Hitachi 3
46
+ ATOK,Awa TOKushima
47
+ ICU,Isolated Crazy Utopia
48
+ BING,Bing Is Not Google
49
+ EOM
50
+ ],[
51
+ {
52
+ "Google"=>"Chrome",
53
+ "Apple"=>"Safari",
54
+ "Opera"=>"Opera",
55
+ "Mozilla"=>"Firefox"
56
+ },<<-EOM
57
+ CoSVON:0.1,,,
58
+ Google,Chrome,,
59
+ Apple,Safari,"",
60
+ Opera,Opera,,""
61
+ Mozilla,Firefox,"",""
62
+ ,,,
63
+ ,,,
64
+ ,,,
65
+ EOM
66
+ ],[
67
+ {
68
+ "no DQ"=>"foo",
69
+ "with DQ"=>"foo",
70
+ "inner DQ"=>"foo\"bar",
71
+ "many DQs"=>"\"\"\"\"\"\"\"\"\""
72
+ },<<-EOM
73
+ CoSVON:0.1
74
+ no DQ,foo
75
+ with DQ,"foo"
76
+ inner DQ,"foo""bar"
77
+ many DQs,""""""""""""""""""""
78
+ EOM
79
+ ],[
80
+ {
81
+ "no extra comma"=>"hoge",
82
+ "extra comma"=>"fuga",
83
+ "extra comma with DQ"=>"piyo",
84
+ "many extra commas"=>"moge"
85
+ },<<-EOM
86
+ CoSVON:0.1
87
+ no extra comma,hoge
88
+ extra comma,fuga,
89
+ extra comma with DQ,piyo,""
90
+ many extra commas,moge,,,,,,,
91
+ "",""
92
+ ,,
93
+ ,"",
94
+ EOM
95
+ ]
96
+ ]
97
+
98
+ describe "CoSVON [default]" do
99
+ cases.each_with_index{|e,i|
100
+ specify "Case #{i+1}" do
101
+ hash=CoSVON.parse(e[1])
102
+ cosvon=CoSVON.stringify(hash)
103
+ CoSVON.parse(cosvon).should eq e[0]
104
+ end
105
+ }
106
+ end
107
+
108
+ describe "CoSVON [CoSVON.csv]" do
109
+ cases.each_with_index{|e,i|
110
+ specify "Case #{i+1}" do
111
+ hash=CoSVON.parse(e[1],CoSVON.method(:csv))
112
+ cosvon=CoSVON.stringify(hash)
113
+ CoSVON.parse(cosvon,CoSVON.method(:csv)).should eq e[0]
114
+ end
115
+ }
116
+ end
117
+
118
+ require 'csv'
119
+ describe "CoSVON [CSV.parse]" do
120
+ cases.each_with_index{|e,i|
121
+ specify "Case #{i+1}" do
122
+ hash=CoSVON.parse(e[1],CSV.method(:parse))
123
+ cosvon=CoSVON.stringify(hash)
124
+ CoSVON.parse(cosvon,CSV.method(:parse)).should eq e[0]
125
+ end
126
+ }
127
+ end
128
+
129
+ if RUBY_VERSION>='1.9'
130
+ describe "CoSVON.csv" do
131
+ specify "Parsing dame backslash" do
132
+ s=File.read(SPEC_DIR+'/hsalskcab.csv',:encoding=>'Windows-31J').encode('UTF-8')
133
+ CoSVON.csv(s).should eq [['Hello "World"','我申"May you have good luck."']]
134
+ end
135
+ end
136
+ end
@@ -0,0 +1 @@
1
+ "Hello ""World""","��\"May you have good luck."""
@@ -0,0 +1,18 @@
1
+ require 'rspec'
2
+ RSpec.configure{|config|
3
+ config.color=true
4
+ }
5
+
6
+ if !defined?(RUBY_ENGINE)||RUBY_ENGINE=='ruby'
7
+ require 'simplecov'
8
+ require 'coveralls'
9
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
10
+ SimpleCov::Formatter::HTMLFormatter,
11
+ Coveralls::SimpleCov::Formatter
12
+ ]
13
+ SimpleCov.start do
14
+ add_filter 'spec'
15
+ end
16
+ end
17
+
18
+ require File.expand_path(File.dirname(__FILE__)+'/../lib/cosvon')
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cosvon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - cielavenir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Comma Separated Value Object Notation
56
+ email:
57
+ - cielartisan@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .coveralls.yml
63
+ - .gitignore
64
+ - .travis.yml
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - cosvon.gemspec
71
+ - lib/cosvon.rb
72
+ - spec/cosvon_spec.rb
73
+ - spec/hsalskcab.csv
74
+ - spec/spec_helper.rb
75
+ homepage: http://github.com/cielavenir/cosvon
76
+ licenses:
77
+ - Ruby License (2-clause BSDL or Artistic)
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
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
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.14
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Comma Separated Value Object Notation
99
+ test_files:
100
+ - spec/cosvon_spec.rb
101
+ - spec/hsalskcab.csv
102
+ - spec/spec_helper.rb