table-query 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ html
2
+ *~
3
+ Gemfile.lock
4
+ gems
5
+ .bundle
6
+ .yardoc
7
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # -*- ruby -*-
2
+
3
+ source :rubygems
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Keita Yamaguchi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # table-query
2
+
3
+ table-query is a Ruby library to query table data by easy way.
4
+
5
+ ## Install
6
+
7
+ You can install table-query by gem:
8
+
9
+ gem install table-query
10
+
11
+ Or checkout from github:
12
+
13
+ git clone git://github.com/keita/table-query.git
14
+
15
+ ## Example
16
+
17
+ table-query consists by table data(CSV format) and the schema(written in Ruby DSL) file.
18
+ For example, simple.csv is:
19
+
20
+ 1,a
21
+ 1,b
22
+ 1,c
23
+ 2,a
24
+ 2,c
25
+ 3,b
26
+
27
+ And the schema file(simple-schema.rb):
28
+
29
+ # data fields schema
30
+ table.define do
31
+ field :number, :int
32
+ field :char, :symbol
33
+ end
34
+
35
+ # query schema that named "number_to_char"
36
+ query.define(:number_to_char) do
37
+ input :number
38
+ output :char
39
+ end
40
+
41
+ # query schema that named "char_to_number"
42
+ query.define(:char_to_number) do
43
+ input :char
44
+ output :number
45
+ end
46
+
47
+ Now we can query table data by number or char like following:
48
+
49
+ table = TableQuery.table("simple.csv")
50
+ table.number_to_char(1).entries # => [:a, :b, :c]
51
+ table.char_to_number(:b).entries # => [1, 3]
52
+
53
+ ## Todo
54
+
55
+ * search tool
56
+ * compile tool(generator from csv to ruby code)
57
+
58
+ ## Licence
59
+
60
+ table-query is free software distributed under MIT licence.
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'Generate API document'
4
+ task 'html' do
5
+ sh "yard doc -o html --hide-void-return --no-api"
6
+ end
7
+
8
+ desc 'Show undocumented function list'
9
+ task 'html:undoc' do
10
+ sh "yard stats --list-undoc --no-api"
11
+ end
@@ -0,0 +1,20 @@
1
+ require 'table-query'
2
+
3
+ path = File.join(File.dirname(__FILE__), "calendar-jp.csv")
4
+ table = TableQuery.table(path)
5
+
6
+ puts "Monday of Feb 2013"
7
+ puts "------------------"
8
+ puts table.wday_to_day(2013, 2, :mon).entries.join(", ")
9
+
10
+ puts "\nNational holiday list"
11
+ puts "---------------------"
12
+ table.national_holiday_list.each do |holiday|
13
+ puts holiday
14
+ end
15
+
16
+ puts "\nFind Friday the 13th in 2013"
17
+ puts "----------------------------"
18
+ table.fri_13th.each do |year, month, mday|
19
+ puts "%d/%d/%d" % [year, month, mday]
20
+ end
@@ -0,0 +1,33 @@
1
+ type.define(:weekday) do
2
+ list = [:sun, :mon, :tue, :wed, :thu, :fri, :sat]
3
+ table = Hash[list.zip((0..6).to_a)]
4
+ to_ruby {|val| list[val.to_i]}
5
+ from_ruby {|val| table[val].to_s}
6
+ end
7
+
8
+ table.define do
9
+ field :year , :int
10
+ field :month , :int
11
+ field :mday , :int
12
+ field :wday , :weekday
13
+ field :national_holiday, :string
14
+ end
15
+
16
+ query.define(:wday_to_day) do
17
+ input :year
18
+ input :month
19
+ input :wday
20
+ output :mday
21
+ end
22
+
23
+ query.define(:national_holiday_list) do
24
+ output :national_holiday, :empty => :ignore
25
+ end
26
+
27
+ query.define(:fri_13th) do
28
+ value :mday, 13
29
+ value :wday, :fri
30
+ output :year
31
+ output :month
32
+ output :mday
33
+ end
@@ -0,0 +1,365 @@
1
+ "2013","1","1","2","元日"
2
+ "2013","1","2","3",""
3
+ "2013","1","3","4",""
4
+ "2013","1","4","5",""
5
+ "2013","1","5","6",""
6
+ "2013","1","6","0",""
7
+ "2013","1","7","1",""
8
+ "2013","1","8","2",""
9
+ "2013","1","9","3",""
10
+ "2013","1","10","4",""
11
+ "2013","1","11","5",""
12
+ "2013","1","12","6",""
13
+ "2013","1","13","0",""
14
+ "2013","1","14","1","成人の日"
15
+ "2013","1","15","2",""
16
+ "2013","1","16","3",""
17
+ "2013","1","17","4",""
18
+ "2013","1","18","5",""
19
+ "2013","1","19","6",""
20
+ "2013","1","20","0",""
21
+ "2013","1","21","1",""
22
+ "2013","1","22","2",""
23
+ "2013","1","23","3",""
24
+ "2013","1","24","4",""
25
+ "2013","1","25","5",""
26
+ "2013","1","26","6",""
27
+ "2013","1","27","0",""
28
+ "2013","1","28","1",""
29
+ "2013","1","29","2",""
30
+ "2013","1","30","3",""
31
+ "2013","1","31","4",""
32
+ "2013","2","1","5",""
33
+ "2013","2","2","6",""
34
+ "2013","2","3","0",""
35
+ "2013","2","4","1",""
36
+ "2013","2","5","2",""
37
+ "2013","2","6","3",""
38
+ "2013","2","7","4",""
39
+ "2013","2","8","5",""
40
+ "2013","2","9","6",""
41
+ "2013","2","10","0",""
42
+ "2013","2","11","1","建国記念の日"
43
+ "2013","2","12","2",""
44
+ "2013","2","13","3",""
45
+ "2013","2","14","4",""
46
+ "2013","2","15","5",""
47
+ "2013","2","16","6",""
48
+ "2013","2","17","0",""
49
+ "2013","2","18","1",""
50
+ "2013","2","19","2",""
51
+ "2013","2","20","3",""
52
+ "2013","2","21","4",""
53
+ "2013","2","22","5",""
54
+ "2013","2","23","6",""
55
+ "2013","2","24","0",""
56
+ "2013","2","25","1",""
57
+ "2013","2","26","2",""
58
+ "2013","2","27","3",""
59
+ "2013","2","28","4",""
60
+ "2013","3","1","5",""
61
+ "2013","3","2","6",""
62
+ "2013","3","3","0",""
63
+ "2013","3","4","1",""
64
+ "2013","3","5","2",""
65
+ "2013","3","6","3",""
66
+ "2013","3","7","4",""
67
+ "2013","3","8","5",""
68
+ "2013","3","9","6",""
69
+ "2013","3","10","0",""
70
+ "2013","3","11","1",""
71
+ "2013","3","12","2",""
72
+ "2013","3","13","3",""
73
+ "2013","3","14","4",""
74
+ "2013","3","15","5",""
75
+ "2013","3","16","6",""
76
+ "2013","3","17","0",""
77
+ "2013","3","18","1",""
78
+ "2013","3","19","2",""
79
+ "2013","3","20","3","春分の日"
80
+ "2013","3","21","4",""
81
+ "2013","3","22","5",""
82
+ "2013","3","23","6",""
83
+ "2013","3","24","0",""
84
+ "2013","3","25","1",""
85
+ "2013","3","26","2",""
86
+ "2013","3","27","3",""
87
+ "2013","3","28","4",""
88
+ "2013","3","29","5",""
89
+ "2013","3","30","6",""
90
+ "2013","3","31","0",""
91
+ "2013","4","1","1",""
92
+ "2013","4","2","2",""
93
+ "2013","4","3","3",""
94
+ "2013","4","4","4",""
95
+ "2013","4","5","5",""
96
+ "2013","4","6","6",""
97
+ "2013","4","7","0",""
98
+ "2013","4","8","1",""
99
+ "2013","4","9","2",""
100
+ "2013","4","10","3",""
101
+ "2013","4","11","4",""
102
+ "2013","4","12","5",""
103
+ "2013","4","13","6",""
104
+ "2013","4","14","0",""
105
+ "2013","4","15","1",""
106
+ "2013","4","16","2",""
107
+ "2013","4","17","3",""
108
+ "2013","4","18","4",""
109
+ "2013","4","19","5",""
110
+ "2013","4","20","6",""
111
+ "2013","4","21","0",""
112
+ "2013","4","22","1",""
113
+ "2013","4","23","2",""
114
+ "2013","4","24","3",""
115
+ "2013","4","25","4",""
116
+ "2013","4","26","5",""
117
+ "2013","4","27","6",""
118
+ "2013","4","28","0",""
119
+ "2013","4","29","1","昭和の日"
120
+ "2013","4","30","2",""
121
+ "2013","5","1","3",""
122
+ "2013","5","2","4",""
123
+ "2013","5","3","5","憲法記念日"
124
+ "2013","5","4","6","みどりの日"
125
+ "2013","5","5","0","こどもの日"
126
+ "2013","5","6","1",""
127
+ "2013","5","7","2",""
128
+ "2013","5","8","3",""
129
+ "2013","5","9","4",""
130
+ "2013","5","10","5",""
131
+ "2013","5","11","6",""
132
+ "2013","5","12","0",""
133
+ "2013","5","13","1",""
134
+ "2013","5","14","2",""
135
+ "2013","5","15","3",""
136
+ "2013","5","16","4",""
137
+ "2013","5","17","5",""
138
+ "2013","5","18","6",""
139
+ "2013","5","19","0",""
140
+ "2013","5","20","1",""
141
+ "2013","5","21","2",""
142
+ "2013","5","22","3",""
143
+ "2013","5","23","4",""
144
+ "2013","5","24","5",""
145
+ "2013","5","25","6",""
146
+ "2013","5","26","0",""
147
+ "2013","5","27","1",""
148
+ "2013","5","28","2",""
149
+ "2013","5","29","3",""
150
+ "2013","5","30","4",""
151
+ "2013","5","31","5",""
152
+ "2013","6","1","6",""
153
+ "2013","6","2","0",""
154
+ "2013","6","3","1",""
155
+ "2013","6","4","2",""
156
+ "2013","6","5","3",""
157
+ "2013","6","6","4",""
158
+ "2013","6","7","5",""
159
+ "2013","6","8","6",""
160
+ "2013","6","9","0",""
161
+ "2013","6","10","1",""
162
+ "2013","6","11","2",""
163
+ "2013","6","12","3",""
164
+ "2013","6","13","4",""
165
+ "2013","6","14","5",""
166
+ "2013","6","15","6",""
167
+ "2013","6","16","0",""
168
+ "2013","6","17","1",""
169
+ "2013","6","18","2",""
170
+ "2013","6","19","3",""
171
+ "2013","6","20","4",""
172
+ "2013","6","21","5",""
173
+ "2013","6","22","6",""
174
+ "2013","6","23","0",""
175
+ "2013","6","24","1",""
176
+ "2013","6","25","2",""
177
+ "2013","6","26","3",""
178
+ "2013","6","27","4",""
179
+ "2013","6","28","5",""
180
+ "2013","6","29","6",""
181
+ "2013","6","30","0",""
182
+ "2013","7","1","1",""
183
+ "2013","7","2","2",""
184
+ "2013","7","3","3",""
185
+ "2013","7","4","4",""
186
+ "2013","7","5","5",""
187
+ "2013","7","6","6",""
188
+ "2013","7","7","0",""
189
+ "2013","7","8","1",""
190
+ "2013","7","9","2",""
191
+ "2013","7","10","3",""
192
+ "2013","7","11","4",""
193
+ "2013","7","12","5",""
194
+ "2013","7","13","6",""
195
+ "2013","7","14","0",""
196
+ "2013","7","15","1","海の日"
197
+ "2013","7","16","2",""
198
+ "2013","7","17","3",""
199
+ "2013","7","18","4",""
200
+ "2013","7","19","5",""
201
+ "2013","7","20","6",""
202
+ "2013","7","21","0",""
203
+ "2013","7","22","1",""
204
+ "2013","7","23","2",""
205
+ "2013","7","24","3",""
206
+ "2013","7","25","4",""
207
+ "2013","7","26","5",""
208
+ "2013","7","27","6",""
209
+ "2013","7","28","0",""
210
+ "2013","7","29","1",""
211
+ "2013","7","30","2",""
212
+ "2013","7","31","3",""
213
+ "2013","8","1","4",""
214
+ "2013","8","2","5",""
215
+ "2013","8","3","6",""
216
+ "2013","8","4","0",""
217
+ "2013","8","5","1",""
218
+ "2013","8","6","2",""
219
+ "2013","8","7","3",""
220
+ "2013","8","8","4",""
221
+ "2013","8","9","5",""
222
+ "2013","8","10","6",""
223
+ "2013","8","11","0",""
224
+ "2013","8","12","1",""
225
+ "2013","8","13","2",""
226
+ "2013","8","14","3",""
227
+ "2013","8","15","4",""
228
+ "2013","8","16","5",""
229
+ "2013","8","17","6",""
230
+ "2013","8","18","0",""
231
+ "2013","8","19","1",""
232
+ "2013","8","20","2",""
233
+ "2013","8","21","3",""
234
+ "2013","8","22","4",""
235
+ "2013","8","23","5",""
236
+ "2013","8","24","6",""
237
+ "2013","8","25","0",""
238
+ "2013","8","26","1",""
239
+ "2013","8","27","2",""
240
+ "2013","8","28","3",""
241
+ "2013","8","29","4",""
242
+ "2013","8","30","5",""
243
+ "2013","8","31","6",""
244
+ "2013","9","1","0",""
245
+ "2013","9","2","1",""
246
+ "2013","9","3","2",""
247
+ "2013","9","4","3",""
248
+ "2013","9","5","4",""
249
+ "2013","9","6","5",""
250
+ "2013","9","7","6",""
251
+ "2013","9","8","0",""
252
+ "2013","9","9","1",""
253
+ "2013","9","10","2",""
254
+ "2013","9","11","3",""
255
+ "2013","9","12","4",""
256
+ "2013","9","13","5",""
257
+ "2013","9","14","6",""
258
+ "2013","9","15","0",""
259
+ "2013","9","16","1","敬老の日"
260
+ "2013","9","17","2",""
261
+ "2013","9","18","3",""
262
+ "2013","9","19","4",""
263
+ "2013","9","20","5",""
264
+ "2013","9","21","6",""
265
+ "2013","9","22","0",""
266
+ "2013","9","23","1","秋分の日"
267
+ "2013","9","24","2",""
268
+ "2013","9","25","3",""
269
+ "2013","9","26","4",""
270
+ "2013","9","27","5",""
271
+ "2013","9","28","6",""
272
+ "2013","9","29","0",""
273
+ "2013","9","30","1",""
274
+ "2013","10","1","2",""
275
+ "2013","10","2","3",""
276
+ "2013","10","3","4",""
277
+ "2013","10","4","5",""
278
+ "2013","10","5","6",""
279
+ "2013","10","6","0",""
280
+ "2013","10","7","1",""
281
+ "2013","10","8","2",""
282
+ "2013","10","9","3",""
283
+ "2013","10","10","4",""
284
+ "2013","10","11","5",""
285
+ "2013","10","12","6",""
286
+ "2013","10","13","0",""
287
+ "2013","10","14","1","体育の日"
288
+ "2013","10","15","2",""
289
+ "2013","10","16","3",""
290
+ "2013","10","17","4",""
291
+ "2013","10","18","5",""
292
+ "2013","10","19","6",""
293
+ "2013","10","20","0",""
294
+ "2013","10","21","1",""
295
+ "2013","10","22","2",""
296
+ "2013","10","23","3",""
297
+ "2013","10","24","4",""
298
+ "2013","10","25","5",""
299
+ "2013","10","26","6",""
300
+ "2013","10","27","0",""
301
+ "2013","10","28","1",""
302
+ "2013","10","29","2",""
303
+ "2013","10","30","3",""
304
+ "2013","10","31","4",""
305
+ "2013","11","1","5",""
306
+ "2013","11","2","6",""
307
+ "2013","11","3","0","文化の日"
308
+ "2013","11","4","1",""
309
+ "2013","11","5","2",""
310
+ "2013","11","6","3",""
311
+ "2013","11","7","4",""
312
+ "2013","11","8","5",""
313
+ "2013","11","9","6",""
314
+ "2013","11","10","0",""
315
+ "2013","11","11","1",""
316
+ "2013","11","12","2",""
317
+ "2013","11","13","3",""
318
+ "2013","11","14","4",""
319
+ "2013","11","15","5",""
320
+ "2013","11","16","6",""
321
+ "2013","11","17","0",""
322
+ "2013","11","18","1",""
323
+ "2013","11","19","2",""
324
+ "2013","11","20","3",""
325
+ "2013","11","21","4",""
326
+ "2013","11","22","5",""
327
+ "2013","11","23","6","勤労感謝の日"
328
+ "2013","11","24","0",""
329
+ "2013","11","25","1",""
330
+ "2013","11","26","2",""
331
+ "2013","11","27","3",""
332
+ "2013","11","28","4",""
333
+ "2013","11","29","5",""
334
+ "2013","11","30","6",""
335
+ "2013","12","1","0",""
336
+ "2013","12","2","1",""
337
+ "2013","12","3","2",""
338
+ "2013","12","4","3",""
339
+ "2013","12","5","4",""
340
+ "2013","12","6","5",""
341
+ "2013","12","7","6",""
342
+ "2013","12","8","0",""
343
+ "2013","12","9","1",""
344
+ "2013","12","10","2",""
345
+ "2013","12","11","3",""
346
+ "2013","12","12","4",""
347
+ "2013","12","13","5",""
348
+ "2013","12","14","6",""
349
+ "2013","12","15","0",""
350
+ "2013","12","16","1",""
351
+ "2013","12","17","2",""
352
+ "2013","12","18","3",""
353
+ "2013","12","19","4",""
354
+ "2013","12","20","5",""
355
+ "2013","12","21","6",""
356
+ "2013","12","22","0",""
357
+ "2013","12","23","1","天皇誕生日"
358
+ "2013","12","24","2",""
359
+ "2013","12","25","3",""
360
+ "2013","12","26","4",""
361
+ "2013","12","27","5",""
362
+ "2013","12","28","6",""
363
+ "2013","12","29","0",""
364
+ "2013","12","30","1",""
365
+ "2013","12","31","2",""