to-arff 0.1.3 → 0.1.4

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: 6e3569cf355dfe5e6d19f6616a99bfa7a734c848
4
- data.tar.gz: 8253d90f77ab8d9745b0fcc35873f50410125008
3
+ metadata.gz: 34acb2ff64dc71ed0c1561d7c1b7ba50409e3d78
4
+ data.tar.gz: a29957cd5465b2cfcb4512ededa9ea336f46d6e5
5
5
  SHA512:
6
- metadata.gz: 58d45ef0093abc7c780220868d6c6e7799ddacb122f2aad3d4d4c599f79170c171b9b136e9c1af911ba16c996d543cf15e3fe19acceed517d33b66c474255534
7
- data.tar.gz: 0444fcf9b5580c49c1782cba7c1abedccef851e38b06174accc337f7aa3fcca6aeaffc4a2d828b13b47090706b1fa6f8279b98da6f33c9bb941a1fa4ad8753af
6
+ metadata.gz: c46e934b65af034c5dd250ad18ce912ec8c4e8629870445605035096db55685b665edebb7d20e370902921a20b03ee5ac05e9403996d478f9dfba2e348c4d37f
7
+ data.tar.gz: 75df7b401b4695a4e2477be5a8c9517998316a4afe6686ba35616ec3442d6d8ac94a00ebca41930a31deac2f2ac9223c356ff3ac2878c9ee813256e516f4cfdb
data/README.md CHANGED
@@ -45,30 +45,52 @@ Or install it yourself as:
45
45
 
46
46
  ###Convert from an SQLite Database
47
47
  #### By Specifying Column Types (Recommended)
48
- Its better to specify column types.
48
+ Use the convert() method and specify the column/attribute types as a json (or nested hash).
49
49
  ```ruby
50
50
  require 'to-arff'
51
- # You can download the file from '/spec /sample_db_files/sample2.db'
52
- sample = ToARFF::SQLiteDB.new "/path/to/sample_sqlite.db"
51
+ # Get the db file from https://github.com/dhrubomoy/to-arff/blob/master/spec/sample_db_files/sample2.db
52
+ sample = ToARFF::SQLiteDB.new "/path/to/sample2.db"
53
53
  # Attribute names and types must be valid
54
- # eg. { "table1" => {"column11"=>"NUMERIC",
54
+ # eg. { "table1": {"column11"=>"NUMERIC",
55
+ # "column12"=>"STRING"
56
+ # },
57
+ # "table2": {"column21"=>"class {Iris-setosa,Iris-versicolor,Iris-virginica}",
58
+ # "column22"=>"DATE \"yyyy-MM-dd HH:mm:ss\""
59
+ # }
60
+ # }
61
+ # OR { "table1" => {"column11"=>"NUMERIC",
55
62
  # "column12"=>"STRING"
56
63
  # },
57
64
  # "table2" => {"column21"=>"class {Iris-setosa,Iris-versicolor,Iris-virginica}",
58
65
  # "column22"=>"DATE \"yyyy-MM-dd HH:mm:ss\""
59
66
  # }
60
- sample_column_types_param = { "employees" => {"EmployeeId"=>"NUMERIC",
67
+ # }
68
+ sample_column_types_param_json = {
69
+ "albums": {
70
+ "Albumid": "NUMERIC",
71
+ "Title": "STRING"
72
+ },
73
+ "employees": {
74
+ "EmployeeId": "NUMERIC",
75
+ "LastName": "STRING",
76
+ "City": "STRING",
77
+ "HireDate": "DATE 'yyyy-MM-dd HH:mm:ss'"
78
+ }
79
+ }
80
+ sample_column_types_param_hash = { "employees" => {"EmployeeId"=>"NUMERIC",
61
81
  "LastName"=>"STRING",
62
82
  "City"=>"STRING",
63
83
  "HireDate"=>"DATE \"yyyy-MM-dd HH:mm:ss\""
64
84
  },
65
- "albums" => { "Albumid"=>"NUMERIC",
66
- "Title"=>"STRING"
67
- }
68
- }
69
- puts sample.convert column_types: sample_column_types_param
85
+ "albums" => { "Albumid"=>"NUMERIC",
86
+ "Title"=>"STRING"
87
+ }
88
+ }
89
+ puts sample.convert column_types: sample_column_types_param_json
90
+ #OR
91
+ puts sample.convert column_types: sample_column_types_param_hash
70
92
  ```
71
- We will get something similar to following:
93
+ Both will produce string similar to following:
72
94
  ```
73
95
  @RELATION employees
74
96
 
@@ -103,12 +125,20 @@ sample = ToARFF::SQLiteDB.new "/path/to/sample_sqlite.db"
103
125
  # { "table1" => ["column11", "column12",...],
104
126
  # "table2" => ["column21", "column22",...]
105
127
  # }
106
- sample_columns = { "albums" => ["AlbumId", "Title", "ArtistId"],
107
- "employees" => ["EmployeeId", "LastName", "FirstName", "Title"]
108
- }
109
- puts sample.convert columns: sample_columns
128
+ # OR
129
+ # { "table1": ["column11", "column12",...],
130
+ # "table2": ["column21", "column22",...]
131
+ # }
132
+ sample_columns_json = { "albums": ["AlbumId", "Title", "ArtistId"],
133
+ "employees": ["EmployeeId", "LastName", "FirstName", "Title"]
134
+ }
135
+ sample_columns_hash = { "albums" => ["AlbumId", "Title", "ArtistId"],
136
+ "employees" => ["EmployeeId", "LastName", "FirstName", "Title"]
137
+ }
138
+ puts sample.convert columns: sample_columns_json
139
+ puts sample.convert columns: sample_columns_hash
110
140
  ```
111
- We will get something similar:
141
+ Both json and hash parameters for `columns:` will return string similar to following:
112
142
  ```
113
143
  @RELATION albums
114
144
 
@@ -153,7 +183,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/dhrubo
153
183
  1. Fork it ( https://github.com/dhrubomoy/to-arff/fork )
154
184
  2. Create branch (`git checkout -b my-new-feature`)
155
185
  3. Make changes. Add test cases for your changes
156
- 4. Run `rspec spec/` and make sure all the test passes
186
+ 4. Run `rake spec/` and make sure all the test passes
157
187
  5. Commit your changes (`git commit -am 'Add some feature'`)
158
188
  6. Push to the branch (`git push origin my-new-feature`)
159
189
  7. Create new Pull Request
@@ -1,5 +1,6 @@
1
1
  require 'to-arff/version'
2
2
  require 'sqlite3'
3
+ require 'json'
3
4
 
4
5
  module ToARFF
5
6
  RELATION_MARKER = '@RELATION'.freeze
@@ -191,6 +192,14 @@ module ToARFF
191
192
  end
192
193
  end
193
194
 
195
+ def stringify_all_keys(hash)
196
+ stringified_hash = {}
197
+ hash.each do |k, v|
198
+ stringified_hash[k.to_s] = v.is_a?(Hash) ? stringify_all_keys(v) : v
199
+ end
200
+ stringified_hash
201
+ end
202
+
194
203
  def convert(options={})
195
204
  temp_tables = options.fetch(:tables, Array.new)
196
205
  temp_columns = options.fetch(:columns, Hash.new)
@@ -205,7 +214,7 @@ module ToARFF
205
214
  if valid_option_given(options)
206
215
  raise ArgumentError.new("Wrong parameter name \":#{options.keys.first}\"")
207
216
  else
208
- deal_with_valid_option(temp_tables, temp_columns, temp_column_types, res)
217
+ deal_with_valid_option(temp_tables, stringify_all_keys(temp_columns), stringify_all_keys(temp_column_types), res)
209
218
  end
210
219
  elsif param_count > 1
211
220
  raise ArgumentError.new("You can specify only one out of the three parameters: table, columns, column_types.")
@@ -1,3 +1,3 @@
1
1
  module ToARFF
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'bundler', '~> 1.12'
24
24
  spec.add_development_dependency 'rake', '~> 11.2'
25
25
  spec.add_development_dependency 'sqlite3', '~> 1.3'
26
+ spec.add_development_dependency 'json'
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to-arff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - dhrubo_moy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-19 00:00:00.000000000 Z
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description:
56
70
  email:
57
71
  - dhrubo_moy@yahoo.com