muzzy 0.1.9 → 0.1.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9a3b80cd33bcfa32e44552ba5b0962a09a0ae2d
4
- data.tar.gz: 87904057f8d81400101c6eeebc4a1aa94389bc30
3
+ metadata.gz: 9fafdd625f30a8271efa806cf9458bb8c1b61ef4
4
+ data.tar.gz: efc95b3c3c81c9d84b679b0adc4484588a191b62
5
5
  SHA512:
6
- metadata.gz: d1fa5c4bcde95423887b42988f25354731e2a525b31a48968d031576cfd5114bff632f78e599124d00190b8c122d15bb76244d4f3caf9783b036729a31d73756
7
- data.tar.gz: b99f6d1bc3d7535edbe0a12050be17f903726d7d0c3a35d127fca6cefb5898778c56c991356e89fdb4db38438074cfdec4bb4779fcaa688d4e33c1a6663b08ea
6
+ metadata.gz: cafee7cee7b9f4d1082d5459395d2f33b713f418108fc50b6409306cbc832f5f9abea1891185c79da4a61b3ba3411f72e2cbc80a5ccc9c1bfdfa333d3188b49b
7
+ data.tar.gz: 661f7617630ff85e2c8effa0ff0e10f67560213d6a0187a75723038fa3e2c0e139f3af40cbfe15da4373fca710d4a7fb567ff0549d00f1b89519e81b5e792c2a
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/README.md CHANGED
@@ -9,7 +9,9 @@ TSV or CSV query program are exist(textql, q, and something like that), but I wa
9
9
 
10
10
  `$ gem install muzzy`
11
11
 
12
- and run muzzy_setup
12
+ and run
13
+
14
+ `$ muzzy_setup`
13
15
 
14
16
  ## Usage
15
17
 
@@ -19,10 +21,53 @@ or
19
21
 
20
22
  `$ muzzy -f filename`
21
23
 
22
-
23
24
  ## Examples
24
25
 
25
- ### Case 1, You have Japanese tsv file
26
+ ### Case 1, trying tsv file.
27
+
28
+ #### ok, Let's execute muzzy.
29
+
30
+ ```
31
+ $ muzzy spec/fixtures/partial_surround_double_quote.tsv
32
+ $ mysql -u root muzzy
33
+ mysql> show create table partial_surround_double_quote;
34
+ ```
35
+
36
+ ```
37
+ +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
38
+ | Table | Create Table |
39
+ +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
40
+ | partial_surround_double_quote | CREATE TABLE `partial_surround_double_quote` (
41
+ `PassengerId` int(11) DEFAULT NULL,
42
+ `Survived` int(11) DEFAULT NULL,
43
+ `Pclass` int(11) DEFAULT NULL,
44
+ `Name` text,
45
+ `Sex` text,
46
+ `Age` int(11) DEFAULT NULL,
47
+ `SibSp` int(11) DEFAULT NULL,
48
+ `Parch` int(11) DEFAULT NULL,
49
+ `Ticket` text,
50
+ `Fare` text,
51
+ `Cabin` text,
52
+ `Embarked` text
53
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
54
+ +-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
55
+ 1 row in set (0.00 sec)
56
+ ```
57
+
58
+ ```
59
+ mysql> select * from partial_surround_double_quote limit 3;
60
+ +-------------+----------+--------+-----------------------------------------------------+--------+------+-------+-------+------------------+---------+-------+----------+
61
+ | PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked |
62
+ +-------------+----------+--------+-----------------------------------------------------+--------+------+-------+-------+------------------+---------+-------+----------+
63
+ | 1 | 0 | 3 | Braund Mr. Owen Harris | male | 22 | 1 | 0 | A/5 21171 | 7.25 | | S
64
+ | 2 | 1 | 1 | Cumings Mrs. John Bradley (Florence Briggs Thayer) | female | 38 | 1 | 0 | PC 17599 | 71.2833 | C85 | C
65
+ | 3 | 1 | 3 | Heikkinen Miss. Laina | female | 26 | 0 | 0 | STON/O2. 3101282 | 7.925 | | S
66
+ +-------------+----------+--------+-----------------------------------------------------+--------+------+-------+-------+------------------+---------+-------+----------+
67
+ 3 rows in set (0.00 sec)
68
+ ```
69
+
70
+ ### Case 2, You have Japanese tsv file
26
71
 
27
72
  You have users.tsv and content is bellow.
28
73
 
@@ -84,6 +129,10 @@ mysql> select * from sample where seibetsu = '男';
84
129
 
85
130
  Thats, it.
86
131
 
132
+ ## Do you want to test now?
133
+ https://raw.githubusercontent.com/rebeccabilbro/titanic/master/data/train.csv
134
+
135
+
87
136
  ## Dependency
88
137
  muzzy uses [kakasi](http://kakasi.namazu.org/index.html.ja) for create table column name.
89
138
 
data/bin/setup CHANGED
@@ -4,13 +4,3 @@ IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
6
  bundle install
7
-
8
- # Do any other automated setup that you need to do here
9
-
10
- ### install kakasi
11
- cd vendor
12
- dir=`ruby -e 'puts Dir.pwd'`
13
- gzip -dc kakasi-2.3.6.tar.gz | tar xvf -
14
- cd kakasi-2.3.6
15
- ./configure --prefix=$dir
16
- make && make install
data/bin/setup_kakasi ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ ### install kakasi
7
+ cd vendor
8
+ dir=`ruby -e 'puts Dir.pwd'`
9
+ gzip -dc kakasi-2.3.6.tar.gz | tar xvf -
10
+ cd kakasi-2.3.6
11
+ ./configure --prefix=$dir
12
+ make && make install
data/exe/muzzy CHANGED
@@ -56,6 +56,7 @@ def check_file(file)
56
56
  end
57
57
  end
58
58
 
59
+ ## parse arguments
59
60
  ARGV.options do |opt|
60
61
  opt.banner = "Usage: muzzy [filepath] [options]"
61
62
  begin
@@ -105,7 +106,7 @@ if options[:mysql_config][:database] !~ /\A(\w)+\z/
105
106
  exit 1
106
107
  end
107
108
 
108
- # confirm database
109
+ ## confirm database, if not, create it.
109
110
  mysql_cmd_list = [mysql_cmd, '-u', options[:mysql_config][:user], '-h', options[:mysql_config][:host]]
110
111
  if options[:mysql_config][:use_password]
111
112
  mysql_cmd_list.push('-p')
@@ -125,72 +126,61 @@ if confirm_database_res == ''
125
126
  end
126
127
  end
127
128
 
128
- def fetch_header_and_first_row(filepath, col_sep)
129
- i = 0
130
- header_row, first_row = nil, nil
131
- CSV.foreach(filepath, col_sep: col_sep) do |row|
132
- if i == 0
133
- header_row = row
134
- elsif i == 1
135
- first_row = row
136
- else
137
- break
138
- end
139
- i += 1
140
- end
141
- return [header_row, first_row]
142
- end
143
-
144
-
145
129
  ## get first and second rows
146
-
147
130
  header_row = []
148
131
  first_row = [] # first row means first data row
149
132
  fields_terminated_by = ","
150
- fields_enclosed_by = ''
151
133
 
152
- File.open(options[:file], mode="rt") do |f|
153
- f.each_char do |c|
154
- if c == '"'
155
- fields_enclosed_by = '"'
156
- end
157
- break
158
- end
159
- end
160
134
 
161
135
  if options[:file] =~ /\.tsv\z/
162
136
  # tsv
163
- header_row, first_row = fetch_header_and_first_row(options[:file], "\t")
137
+ header_row, first_row = Muzzy::Util.fetch_header_and_first_row(options[:file], "\t")
164
138
  fields_terminated_by = "\t"
165
139
  else
166
140
  # csv(,) or csv(\t) or something
167
141
 
168
142
  # trying to csv
169
- csv_header_row, csv_first_row = fetch_header_and_first_row(options[:file], ",")
143
+ csv_header_row, csv_first_row = Muzzy::Util.fetch_header_and_first_row(options[:file], ",")
170
144
  # trying to tsv
171
- tsv_header_row, tsv_first_row = fetch_header_and_first_row(options[:file], "\t")
145
+ tsv_header_row, tsv_first_row = Muzzy::Util.fetch_header_and_first_row(options[:file], "\t")
172
146
 
173
- if csv_header_row.length == tsv_header_row.length
174
- if csv_header_row.length == 1 && tsv_first_row.length == 1
175
- # single col file
176
- header_row, first_row = csv_header_row, csv_first_row
177
- else
178
- puts "illegal file"
179
- exit 1
180
- end
147
+ if csv_header_row == -1 && tsv_header_row == -1
148
+ puts "illegal csv file."
149
+ exit 1
181
150
  end
182
151
 
183
- if csv_header_row.length > tsv_header_row.length
184
- # csv
185
- header_row, first_row = csv_header_row, csv_first_row
152
+ if csv_header_row == -1 || tsv_header_row == -1
153
+ if csv_header_row == -1
154
+ # tsv
155
+ header_row, first_row = tsv_header_row, tsv_first_row
156
+ fields_terminated_by = "\t"
157
+ else
158
+ # csv
159
+ header_row, first_row = csv_header_row, csv_first_row
160
+ end
186
161
  else
187
- # tsv
188
- header_row, first_row = tsv_header_row, tsv_first_row
189
- fields_terminated_by = "\t"
162
+ if csv_header_row.length > tsv_header_row.length
163
+ # csv
164
+ header_row, first_row = csv_header_row, csv_first_row
165
+ else
166
+ # tsv
167
+ header_row, first_row = tsv_header_row, tsv_first_row
168
+ fields_terminated_by = "\t"
169
+ end
170
+ if csv_header_row.length == tsv_header_row.length
171
+ if csv_header_row.length == 1 && tsv_first_row.length == 1
172
+ # single col file
173
+ header_row, first_row = csv_header_row, csv_first_row
174
+ else
175
+ puts "illegal file"
176
+ exit 1
177
+ end
178
+ end
190
179
  end
191
180
  end
192
181
  header_row = header_row.map(&:to_s)
193
182
 
183
+
194
184
  # guess header_row is data row or not
195
185
  header_row_is_header = nil
196
186
 
@@ -198,6 +188,8 @@ if header_row.any?{|str| str.match(/_id/) }
198
188
  header_row_is_header = true
199
189
  elsif header_row.any?{|str| str.match(/NULL/) }
200
190
  header_row_is_header = false
191
+ elsif header_row.any?{|str| str.nil? || str == '' }
192
+ header_row_is_header = false
201
193
  elsif header_row.map(&:to_i).select{|x| x <= 0}.count != first_row.map(&:to_i).select{|x| x <= 0}.count
202
194
  # i guess number col count is different, header_row is header.
203
195
  header_row_is_header = true
@@ -233,7 +225,7 @@ end
233
225
  Cell = Struct.new(:type, :name)
234
226
  if header_row_is_header
235
227
  row_data_types = first_row.map.with_index do |str, i|
236
- if str.match(/\A[\d,]+\z/)
228
+ if str.to_s.match(/\A[\d,]+\z/)
237
229
  # number
238
230
  Cell.new('integer', header_row[i])
239
231
  else
@@ -243,7 +235,7 @@ if header_row_is_header
243
235
  else
244
236
  # header row is data
245
237
  row_data_types = header_row.map.with_index do |str, i|
246
- if str.match(/\A[\d,]+\z/)
238
+ if str.to_s.match(/\A[\d,]+\z/)
247
239
  # number
248
240
  Cell.new('integer', "col#{i}")
249
241
  else
@@ -288,9 +280,7 @@ end
288
280
  if options[:mysqlimport_config][:delete]
289
281
  cmds.push('--delete')
290
282
  end
291
- if fields_enclosed_by != ''
292
- cmds.push("--fields_enclosed_by=#{fields_enclosed_by}")
293
- end
283
+ cmds.push('--fields_enclosed_by="')
294
284
 
295
285
  if options[:verbose]
296
286
  puts cmds.join(' ')
data/exe/muzzy_setup CHANGED
@@ -1,3 +1,3 @@
1
1
  lib_root_path = File.absolute_path(File.expand_path('.', __FILE__) + "/../../")
2
- setup_path = "#{lib_root_path}/bin/setup"
2
+ setup_path = "#{lib_root_path}/bin/setup_kakasi"
3
3
  `cd #{lib_root_path} && #{setup_path}`
@@ -0,0 +1,4 @@
1
+ module Muzzy
2
+ class FiletypeDetector
3
+ end
4
+ end
data/lib/muzzy/util.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'csv'
2
+ module Muzzy
3
+ class Util
4
+ def self.fetch_header_and_first_row(filepath, col_sep)
5
+ raise ArgumentError, "filepath required" if filepath.nil?
6
+ raise ArgumentError, "not found file" unless File.exists?(filepath)
7
+ header_row, first_row = nil, nil
8
+ CSV.foreach(filepath, col_sep: col_sep).each_with_index do |row, i|
9
+ if i == 0
10
+ header_row = row
11
+ elsif i == 1
12
+ first_row = row
13
+ else
14
+ break
15
+ end
16
+ end
17
+ return [header_row, first_row]
18
+ rescue ArgumentError => e
19
+ raise e
20
+ rescue => e
21
+ return [-1, -1]
22
+ end
23
+ end
24
+ end
data/lib/muzzy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Muzzy
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.11"
3
3
  end
data/lib/muzzy.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "muzzy/version"
1
+ require 'muzzy/version'
2
+ require_relative 'muzzy/util'
2
3
 
3
4
  module Muzzy
4
- # Your code goes here...
5
5
  end
data/muzzy.gemspec CHANGED
@@ -31,5 +31,6 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 1.15"
33
33
  spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "minitest", "~> 5.0"
34
+ spec.add_development_dependency "rspec", "~> 3.8"
35
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
35
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muzzy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - vimtaku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-07 00:00:00.000000000 Z
11
+ date: 2018-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,19 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.0'
47
+ version: '3.8'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.0'
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.7'
55
69
  description: muzzy is tsv importer mysql client
56
70
  email:
57
71
  - vimtaku@gmail.com
@@ -62,17 +76,22 @@ extensions: []
62
76
  extra_rdoc_files: []
63
77
  files:
64
78
  - ".gitignore"
79
+ - ".rspec"
65
80
  - ".travis.yml"
66
81
  - CODE_OF_CONDUCT.md
67
82
  - Gemfile
83
+ - Guardfile
68
84
  - LICENSE.txt
69
85
  - README.md
70
86
  - Rakefile
71
87
  - bin/console
72
88
  - bin/setup
89
+ - bin/setup_kakasi
73
90
  - exe/muzzy
74
91
  - exe/muzzy_setup
75
92
  - lib/muzzy.rb
93
+ - lib/muzzy/filetype_detector.rb
94
+ - lib/muzzy/util.rb
76
95
  - lib/muzzy/version.rb
77
96
  - muzzy.gemspec
78
97
  - vendor/kakasi-2.3.6.tar.gz