garb 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -19,6 +19,7 @@ spec = Gem::Specification.new do |s|
19
19
  s.test_files = Dir.glob("test/**/*")
20
20
 
21
21
  s.add_dependency("happymapper", ["~> 0.3.0"])
22
+ s.add_dependency("activesupport", [">= 2.3.0"])
22
23
  end
23
24
 
24
25
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -1,12 +1,4 @@
1
1
  class String
2
- def underscored
3
- self.gsub(/([A-Z])/, '_\1').downcase
4
- end
5
-
6
- def lower_camelized
7
- self.gsub(/(_)(.)/) { $2.upcase }
8
- end
9
-
10
2
  def to_ga
11
3
  "ga:#{self}"
12
4
  end
@@ -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
- "ga:#{self.to_s.lower_camelized}"
34
+ self.to_s.camelize(:lower).to_ga
35
35
  end
36
- end
36
+ end
@@ -2,10 +2,11 @@ $:.unshift File.expand_path(File.dirname(__FILE__))
2
2
 
3
3
  require 'net/http'
4
4
  require 'net/https'
5
- require 'rubygems'
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
@@ -13,7 +13,7 @@ module Garb
13
13
  attribute :value, String
14
14
 
15
15
  def instance_name
16
- name.from_ga.underscored
16
+ name.from_ga.underscore
17
17
  end
18
18
  end
19
19
 
@@ -13,12 +13,12 @@ module Garb
13
13
  hash = {}
14
14
 
15
15
  entry.metrics.each do |m|
16
- name = m.name.sub(/^ga\:/,'').underscored
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\:/,'').underscored
21
+ name = d.name.sub(/^ga\:/,'').underscore
22
22
  hash.merge!({name => d.value})
23
23
  end
24
24
 
@@ -3,7 +3,7 @@ module Garb
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- TINY = 0
6
+ TINY = 1
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
@@ -1,37 +1,39 @@
1
1
  require File.join(File.dirname(__FILE__), '..', '/test_helper')
2
2
 
3
- class OperatorTest < MiniTest::Unit::TestCase
4
- context "An instance of an Operator" do
5
- should "lower camelize the target" do
6
- assert_equal "ga:uniqueVisits=", Operator.new(:unique_visits, "=").to_ga
7
- end
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
- should "return target and operator together" do
10
- assert_equal "ga:metric=", Operator.new(:metric, "=").to_ga
11
- end
10
+ should "return target and operator together" do
11
+ assert_equal "ga:metric=", Operator.new(:metric, "=").to_ga
12
+ end
12
13
 
13
- should "prefix the operator to the target" do
14
- assert_equal "-ga:metric", Operator.new(:metric, "-", true).to_ga
15
- end
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
- should "know if it is equal to another operator" do
18
- op1 = Operator.new(:hello, "==")
19
- op2 = Operator.new(:hello, "==")
20
- assert_equal op1, op2
21
- end
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
- should "not be equal to another operator if target, operator, or prefix is different" do
24
- op1 = Operator.new(:hello, "==")
25
- op2 = Operator.new(:hello, "==", true)
26
- refute_equal op1, op2
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
- op1 = Operator.new(:hello1, "==")
29
- op2 = Operator.new(:hello2, "==")
30
- refute_equal op1, op2
29
+ op1 = Operator.new(:hello1, "==")
30
+ op2 = Operator.new(:hello2, "==")
31
+ refute_equal op1, op2
31
32
 
32
- op1 = Operator.new(:hello, "!=")
33
- op2 = Operator.new(:hello, "==")
34
- refute_equal op1, op2
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
@@ -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.0
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
@@ -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