directiverecord 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWExODBiMTQ1NGVmYjU5MmE1ZGI4ZGE2MGI4ZWY2OWNhYjc0YWM1Yw==
4
+ YjcwZWZhNjNhZThlMWQyOWU4NGIyNzE1YTRiNjQ5N2UzYWE2OGUzYQ==
5
5
  data.tar.gz: !binary |-
6
- OTM3ZTk5NDY0OTBiZDc5NDY1NTEyNjJjYjkyYjQ4ZTZkN2MyODUyMg==
6
+ NjcxNWM5NTc2NzEzZTNiNTUwNjczMTA4MjAzMzUwMGViMTYzMjRlNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGQ1MzBhNTZkZGRjZmU2ODA5OGUyNDY1NDM0NmNhYzE5YWYxYTVjYTEyMWI3
10
- OWQ0ODhiZDVjZjY2M2RiNGYxNTgxNjVlMWVkMzMzMTZlMjM4ZGRlZDRlYzFm
11
- Njg5YWZjOGFhZjI4NTcwZGYyYTI0NjAyZWVjZGI1YWZkYmQyZTk=
9
+ NGFkZTNiN2EyN2NhZTc4YjE0ZjY2MjE0M2EwMGZiYjc2OGZjODk4OTE5MjZm
10
+ ZTIzZWQ3ZTRjODU3YWYxMDhmOTJiNTgwMWM1ODZmZWM3OTc1YzQ4YTczZjVi
11
+ Y2M3YWRiYjYxZTllNzIxMzU4MzFlMzQ3MDBiMTllNzMwYjdiNjY=
12
12
  data.tar.gz: !binary |-
13
- NjFjNTE4ZmMzMWFkYjUxYzYzZDBhMmYzODA1N2FlODU3Mjg4NjFhNjI3ZDM4
14
- ZjVhZGIyYzM3MjViMDQ4OTVmNjQwNzNlN2U4MjMyOTY1YTE3NDFiY2QzZDYw
15
- ODBjMmMwOTQxNWI5ODAzYzE0NTNlMDg5NDRiMTUyMmRjZDBkNWI=
13
+ MDhmZWNlZDY2Njc1OWM4ZjM4NzkxMWI3ODhmMTJjZDU5NmM2MDU5M2YxNWJj
14
+ Y2Y5YWI4MGJhNTRmOTI1MWU5ZTc0M2Y3Y2VjMzUyNjBjOTk4Y2FjMjA2MTUz
15
+ OTU4NzE2M2E2YmM3YTA4OTZlOGIwMDBlYzdiMGM2MGYyMDk1MWQ=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = DirectiveRecord CHANGELOG
2
2
 
3
+ == Version 0.1.3 (January 21, 2015)
4
+
5
+ * Added trend query support
6
+
3
7
  == Version 0.1.2 (January 21, 2015)
4
8
 
5
9
  * Downgraded ActiveRecord gem dependency to >= 3.2.13
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -9,6 +9,10 @@ module ActiveRecord
9
9
  extract_connection(args).select_rows to_qry(*args)
10
10
  end
11
11
 
12
+ def self.to_trend_qry(q1, q2, join_column_count, options)
13
+ DirectiveRecord::Query.new(self).to_trend_sql(q1, q2, join_column_count, options)
14
+ end
15
+
12
16
  private
13
17
 
14
18
  def self.extract_connection(args)
@@ -25,6 +25,23 @@ module DirectiveRecord
25
25
  compose_sql options
26
26
  end
27
27
 
28
+ def to_trend_sql(q1, q2, join_column_count, options)
29
+ i = join_column_count + 1
30
+ select = "q1.*, q2.c#{i}, (((q1.c#{i} - q2.c#{i}) / ABS(q2.c#{i})) * 100) AS trend"
31
+ on = (1..join_column_count).to_a.collect{|x| "q1.c#{x} = q2.c#{x}"}.join(" AND ")
32
+ order = "\nORDER BY #{options[:order]}" if options[:order]
33
+ limit = "\nLIMIT #{options[:limit]}" if options[:limit]
34
+ offset = "\nOFFSET #{options[:offset]}" if options[:offset]
35
+ <<-SQL
36
+ SELECT #{select}
37
+ FROM
38
+ (\n#{q1}\n) q1
39
+ INNER JOIN
40
+ (\n#{q2}\n) q2
41
+ ON #{on}#{order}#{limit}#{offset}
42
+ SQL
43
+ end
44
+
28
45
  private
29
46
 
30
47
  def path_delimiter; end
@@ -1,7 +1,7 @@
1
1
  module DirectiveRecord
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 2
4
+ TINY = 3
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directiverecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel