garb 0.4.0 → 0.4.1
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.
- data/Rakefile +1 -0
- data/lib/extensions/string.rb +0 -8
- data/lib/extensions/symbol.rb +4 -4
- data/lib/garb.rb +3 -2
- data/lib/garb/operator.rb +22 -0
- data/lib/garb/profile.rb +1 -1
- data/lib/garb/report_response.rb +2 -2
- data/lib/garb/version.rb +1 -1
- data/test/unit/operator_test.rb +29 -27
- data/test/unit/symbol_test.rb +2 -2
- metadata +12 -2
- data/lib/extensions/operator.rb +0 -20
data/Rakefile
CHANGED
data/lib/extensions/string.rb
CHANGED
data/lib/extensions/symbol.rb
CHANGED
@@ -5,7 +5,7 @@ class Symbol
|
|
5
5
|
operators.each do |method, operator|
|
6
6
|
class_eval <<-CODE
|
7
7
|
def #{method}
|
8
|
-
Operator.new(self, '#{operator}')
|
8
|
+
Garb::Operator.new(self, '#{operator}')
|
9
9
|
end
|
10
10
|
CODE
|
11
11
|
end
|
@@ -13,7 +13,7 @@ class Symbol
|
|
13
13
|
|
14
14
|
# Sorting
|
15
15
|
def desc
|
16
|
-
Operator.new(self, '-', true)
|
16
|
+
Garb::Operator.new(self, '-', true)
|
17
17
|
end
|
18
18
|
|
19
19
|
operator :eql => '==',
|
@@ -31,6 +31,6 @@ class Symbol
|
|
31
31
|
|
32
32
|
# Metric filters
|
33
33
|
def to_ga
|
34
|
-
|
34
|
+
self.to_s.camelize(:lower).to_ga
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
data/lib/garb.rb
CHANGED
@@ -2,10 +2,11 @@ $:.unshift File.expand_path(File.dirname(__FILE__))
|
|
2
2
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'net/https'
|
5
|
-
|
5
|
+
|
6
6
|
require 'cgi'
|
7
7
|
require 'ostruct'
|
8
8
|
require 'happymapper'
|
9
|
+
require 'active_support'
|
9
10
|
|
10
11
|
require 'garb/version'
|
11
12
|
require 'garb/authentication_request'
|
@@ -17,9 +18,9 @@ require 'garb/report_parameter'
|
|
17
18
|
require 'garb/report_response'
|
18
19
|
require 'garb/resource'
|
19
20
|
require 'garb/report'
|
21
|
+
require 'garb/operator'
|
20
22
|
|
21
23
|
require 'extensions/string'
|
22
|
-
require 'extensions/operator'
|
23
24
|
require 'extensions/symbol'
|
24
25
|
require 'extensions/array'
|
25
26
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Concept from dm-core
|
2
|
+
module Garb
|
3
|
+
class Operator
|
4
|
+
attr_reader :target, :operator, :prefix
|
5
|
+
|
6
|
+
def initialize(target, operator, prefix=false)
|
7
|
+
@target = target.to_ga
|
8
|
+
@operator = operator
|
9
|
+
@prefix = prefix
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_ga
|
13
|
+
@prefix ? "#{operator}#{target}" : "#{target}#{operator}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(rhs)
|
17
|
+
target == rhs.target &&
|
18
|
+
operator == rhs.operator &&
|
19
|
+
prefix == rhs.prefix
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/garb/profile.rb
CHANGED
data/lib/garb/report_response.rb
CHANGED
@@ -13,12 +13,12 @@ module Garb
|
|
13
13
|
hash = {}
|
14
14
|
|
15
15
|
entry.metrics.each do |m|
|
16
|
-
name = m.name.sub(/^ga\:/,'').
|
16
|
+
name = m.name.sub(/^ga\:/,'').underscore
|
17
17
|
hash.merge!({name => m.value})
|
18
18
|
end
|
19
19
|
|
20
20
|
entry.dimensions.each do |d|
|
21
|
-
name = d.name.sub(/^ga\:/,'').
|
21
|
+
name = d.name.sub(/^ga\:/,'').underscore
|
22
22
|
hash.merge!({name => d.value})
|
23
23
|
end
|
24
24
|
|
data/lib/garb/version.rb
CHANGED
data/test/unit/operator_test.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '/test_helper')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Garb
|
4
|
+
class OperatorTest < MiniTest::Unit::TestCase
|
5
|
+
context "An instance of an Operator" do
|
6
|
+
should "lower camelize the target" do
|
7
|
+
assert_equal "ga:uniqueVisits=", Operator.new(:unique_visits, "=").to_ga
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
should "return target and operator together" do
|
11
|
+
assert_equal "ga:metric=", Operator.new(:metric, "=").to_ga
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
should "prefix the operator to the target" do
|
15
|
+
assert_equal "-ga:metric", Operator.new(:metric, "-", true).to_ga
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
should "know if it is equal to another operator" do
|
19
|
+
op1 = Operator.new(:hello, "==")
|
20
|
+
op2 = Operator.new(:hello, "==")
|
21
|
+
assert_equal op1, op2
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
should "not be equal to another operator if target, operator, or prefix is different" do
|
25
|
+
op1 = Operator.new(:hello, "==")
|
26
|
+
op2 = Operator.new(:hello, "==", true)
|
27
|
+
refute_equal op1, op2
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
op1 = Operator.new(:hello1, "==")
|
30
|
+
op2 = Operator.new(:hello2, "==")
|
31
|
+
refute_equal op1, op2
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
op1 = Operator.new(:hello, "!=")
|
34
|
+
op2 = Operator.new(:hello, "==")
|
35
|
+
refute_equal op1, op2
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
37
|
-
end
|
39
|
+
end
|
data/test/unit/symbol_test.rb
CHANGED
@@ -12,7 +12,7 @@ class SymbolTest < MiniTest::Unit::TestCase
|
|
12
12
|
operator = stub()
|
13
13
|
symbol = :foo
|
14
14
|
|
15
|
-
Operator.expects(:new).with(:foo, '-', true).returns(operator)
|
15
|
+
Garb::Operator.expects(:new).with(:foo, '-', true).returns(operator)
|
16
16
|
assert_equal operator, :foo.desc
|
17
17
|
end
|
18
18
|
|
@@ -22,7 +22,7 @@ class SymbolTest < MiniTest::Unit::TestCase
|
|
22
22
|
new_operator = stub()
|
23
23
|
symbol = :foo
|
24
24
|
|
25
|
-
Operator.expects(:new).with(:foo, operator).returns(new_operator)
|
25
|
+
Garb::Operator.expects(:new).with(:foo, operator).returns(new_operator)
|
26
26
|
assert_equal new_operator, :foo.send(method)
|
27
27
|
end
|
28
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
@@ -23,6 +23,16 @@ dependencies:
|
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: 0.3.0
|
25
25
|
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activesupport
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.3.0
|
35
|
+
version:
|
26
36
|
description:
|
27
37
|
email: tony.pitale@viget.com
|
28
38
|
executables: []
|
@@ -35,13 +45,13 @@ files:
|
|
35
45
|
- README.md
|
36
46
|
- Rakefile
|
37
47
|
- lib/extensions/array.rb
|
38
|
-
- lib/extensions/operator.rb
|
39
48
|
- lib/extensions/string.rb
|
40
49
|
- lib/extensions/symbol.rb
|
41
50
|
- lib/garb/account.rb
|
42
51
|
- lib/garb/authentication_request.rb
|
43
52
|
- lib/garb/data_request.rb
|
44
53
|
- lib/garb/oauth_session.rb
|
54
|
+
- lib/garb/operator.rb
|
45
55
|
- lib/garb/profile.rb
|
46
56
|
- lib/garb/report.rb
|
47
57
|
- lib/garb/report_parameter.rb
|
data/lib/extensions/operator.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# Concept from dm-core
|
2
|
-
class Operator
|
3
|
-
attr_reader :target, :operator, :prefix
|
4
|
-
|
5
|
-
def initialize(target, operator, prefix=false)
|
6
|
-
@target = target.to_ga
|
7
|
-
@operator = operator
|
8
|
-
@prefix = prefix
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_ga
|
12
|
-
@prefix ? "#{operator}#{target}" : "#{target}#{operator}"
|
13
|
-
end
|
14
|
-
|
15
|
-
def ==(rhs)
|
16
|
-
target == rhs.target &&
|
17
|
-
operator == rhs.operator &&
|
18
|
-
prefix == rhs.prefix
|
19
|
-
end
|
20
|
-
end
|