grapher 0.0.1 → 0.0.2

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.
@@ -6,21 +6,29 @@ module Grapher
6
6
  def initialize(time_units, options, block)
7
7
  @time_units = time_units
8
8
  @options = options
9
-
10
- @strf = "%Y-%m-%d"
11
- if @time_units.downcase == "hour"
12
- @strf = "%Y-%m-%d %H:00"
13
- elsif @time_units.downcase == "day"
9
+ @driver = ActiveRecord::Base.connection.instance_values["config"][:adapter]
10
+
11
+ if @driver =~ /postgre/
12
+ @strf = "YYYY-MM-DD"
13
+ if @time_units.downcase == "hour"
14
+ @strf = "%Y-%m-%d %H:00"
15
+ elsif @time_units.downcase == "month"
16
+ @strf = "YYYY-MM-1"
17
+ end
18
+ else
14
19
  @strf = "%Y-%m-%d"
15
- elsif @time_units.downcase == "month"
16
- @strf = "%Y-%m-1"
20
+ if @time_units.downcase == "hour"
21
+ @strf = "%Y-%m-%d %H:00"
22
+ elsif @time_units.downcase == "month"
23
+ @strf = "%Y-%m-1"
24
+ end
17
25
  end
18
26
 
19
27
  block.call(self)
20
28
  end
21
29
 
22
30
  def line(relation, options={})
23
- driver = ActiveRecord::Base.connection.instance_values["config"][:adapter]
31
+
24
32
 
25
33
  @data ||= []
26
34
  @labels ||= []
@@ -28,11 +36,11 @@ module Grapher
28
36
  label = options[:label] || "Value"
29
37
  @labels << label
30
38
 
31
- if driver =~ /mysql/
32
- relation = relation.group("DATE_FORMAT(#{@column}, '#{@strf}')")
33
- elsif driver =~ /postgre/
39
+ if @driver =~ /mysql/
34
40
  relation = relation.group("DATE_FORMAT(#{@column}, '#{@strf}')")
35
- elsif driver =~ /sqlite/
41
+ elsif @driver =~ /postgre/
42
+ relation = relation.group("to_char(#{@column}, '#{@strf}')")
43
+ elsif @driver =~ /sqlite/
36
44
  relation = relation.group("STRFTIME('#{@strf}', #{@column})")
37
45
  end
38
46
 
@@ -1,3 +1,3 @@
1
1
  module Grapher
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grapher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails