chicrime 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 296f179810cd2694aa58f4f589058d28be6f60f0
4
- data.tar.gz: 1fd9f41c5505fe9185933034be471af841e8d883
3
+ metadata.gz: f69c25653031948cc4523c954cb81c811d1d2027
4
+ data.tar.gz: 5c9f5345113f7f8fcc413c30b1d9f88a30da8ab6
5
5
  SHA512:
6
- metadata.gz: f23afe47732fc570ed6aea12f3ab3a7620128012111da6b60f1cc4caf28d99be2c63f4d4f34e2008f3fb1a912b2de3d45c9133b696b8de2eedeb7a9b6bc5ea3e
7
- data.tar.gz: 3588317ce41f7941395446a9951893620724fac84a604c048290668566932acebc755ac7b9226652427848802e7f5391fa6041b979012234e23845b1a6200390
6
+ metadata.gz: 15b2527ee7d4be8144035bdcffa36efae959b2630668cf56bc0f84f7cfeb71f34f8c159749ce6ec8d081b7b0793c6466343a1cd7e9582854805eabc5fe5c5896
7
+ data.tar.gz: 6d522998fbbb7d2f42b6d89c3ad23b2272a6572298f24c011ef8530358d3adf1b0f87ca4dc8d40789572cf0a837c48e7dd8217423b463371527dd2ef4c80eca7
data/README.md CHANGED
@@ -45,6 +45,16 @@ chicrime.where("within_circle(location, 41.8719708, -87.6492965, 500)").order("d
45
45
 
46
46
  # Get results
47
47
  chicrime.where("year = '2014'", "community_area = '1'").order("date").results
48
+
49
+ # New semi-working DSL
50
+ chicrime.query do
51
+ where do
52
+ year equals 2014
53
+ end
54
+ order :id, :desc
55
+ limit 15
56
+ select :arrest, :date, :location
57
+ end
48
58
  ```
49
59
 
50
60
  ## Resources
@@ -57,7 +67,10 @@ chicrime.where("year = '2014'", "community_area = '1'").order("date").results
57
67
 
58
68
  ## Development
59
69
 
60
- TODO: Implement group query & documentation
70
+ TODO
71
+ - Implement group query
72
+ - Documentation
73
+ - Hash support for method queries
61
74
 
62
75
  ## Contributing
63
76
 
data/example.rb ADDED
@@ -0,0 +1,25 @@
1
+ load 'lib/chicrime.rb'
2
+
3
+ c = Chicrime::Dataset.new
4
+
5
+ #results = c.client.get(c.dataset_id, {"$where" => "year = 2014 AND ward = 15",
6
+ # "$order" => "id DESC",
7
+ # "$select" => "ward, id, year",
8
+ # "$limit" => "6"})
9
+
10
+ #results = c.where("year = 2014 AND ward = 15").order(:id, :desc).select(:ward, :id, :year).limit(6).results
11
+
12
+ results =
13
+
14
+ c.query do
15
+
16
+ where do
17
+ year equals 2014
18
+ ward equals 15
19
+ end
20
+
21
+ order :id, :desc
22
+ limit 1
23
+ end
24
+
25
+ puts results
@@ -1,3 +1,3 @@
1
1
  module Chicrime
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/chicrime.rb CHANGED
@@ -3,40 +3,67 @@ require "soda/client"
3
3
 
4
4
  module Chicrime
5
5
  class Dataset
6
- attr_accessor :client, :query
6
+ attr_accessor :client, :soql
7
7
  attr_reader :dataset_id
8
8
 
9
9
  def initialize token=''
10
10
  @client = SODA::Client.new({:domain => 'data.cityofchicago.org', :app_token => token})
11
11
  @dataset_id = 'ijzp-q8t2'
12
- @query = {}
12
+ @soql = {}
13
13
  end
14
14
 
15
- def where *args
16
- query = args.count > 0 ? args * " AND " : ""
17
- @query.store("$where", "#{query}")
15
+ def query &block
16
+ @soql = {}
17
+ instance_eval(&block)
18
+ results
19
+ end
20
+
21
+ def method_missing m, *args, &block
22
+ if soql["$where"]
23
+ prev = soql["$where"] + " AND"
24
+ else
25
+ prev = ""
26
+ end
27
+
28
+ q = "#{prev} #{m} #{args[0]} #{args[1]}".strip
29
+
30
+ @soql.store("$where", "#{q}")
31
+ end
32
+
33
+ def equals data
34
+ "= #{data}"
35
+ end
36
+
37
+ def where *args, &block
38
+ if block_given?
39
+ instance_eval(&block)
40
+ else
41
+ q = args.count > 0 ? args * " AND " : ""
42
+ @soql.store("$where", "#{q}")
43
+ end
44
+
18
45
  self
19
46
  end
20
47
 
21
48
  def limit n
22
- query = n
23
- @query.store("$limit", "#{query}")
49
+ @soql.store("$limit", "#{n}")
24
50
  self
25
51
  end
26
52
 
27
53
  def select *args
28
- query = args.count > 0 ? args * ', ' : ''
29
- @query.store("$select", "#{query}")
54
+ q = args.count > 0 ? args * ', ' : ''
55
+ @soql.store("$select", "#{q}")
30
56
  self
31
57
  end
32
58
 
33
59
  def order column, order=:ASC
34
- @query.store("$order", "#{column} #{order}")
60
+ @soql.store("$order", "#{column} #{order}")
35
61
  self
36
62
  end
37
63
 
38
64
  def results
39
- @client.get(@dataset_id, @query)
65
+ puts @soql
66
+ @client.get(@dataset_id, @soql)
40
67
  end
41
68
  end
42
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chicrime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Roberts
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-08 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -211,6 +211,7 @@ files:
211
211
  - bin/console
212
212
  - bin/setup
213
213
  - chicrime.gemspec
214
+ - example.rb
214
215
  - lib/chicrime.rb
215
216
  - lib/chicrime/version.rb
216
217
  homepage: http://www.codyjroberts.com