hisui 0.1.6 → 0.1.7

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
  SHA256:
3
- metadata.gz: 539f07615132804cd99b435af49bfb73380983d58b967a16d9326dde055ca47c
4
- data.tar.gz: 7cb0f27599b5e2fa28fd947ea0db9aacaa9f669bf6d6b301baba108d7bd892c2
3
+ metadata.gz: 3208e00862c06d44baea1a6ab70be93b9a29834b69246e8e95a7f2543031677a
4
+ data.tar.gz: 4bcc60e4780dd8c7d48402a36b2aa35ec1b69b9d56c1f53c4274c3c310192006
5
5
  SHA512:
6
- metadata.gz: dbdf33eeb8906f14d19c7eb14fa3e90f3be7819beca4a9d408d468e4059aa92c1784cf6926dc61f1bfc8e6bdd32518d1b1b735d7fe732397f58b67cb258ed90e
7
- data.tar.gz: 55ed36f65dff20ea4d59af454638049db05588b9251a717014b1862589dbf3ad03ba693e9cf6b8aa962c38f302460fd9d41af4cb26e12e21ca97ec1d95e4b5c4
6
+ metadata.gz: efedfb4a7eb17259412725397350bdfd3af2cdcdac711495b9b804a7d00b8bbf09c37eeb71cb9879906443255b95a773c2a1da975858258042724f952ae8d0cb
7
+ data.tar.gz: 8804beedc7a904e8728ee99e5ad8e3f3adbd0d5514bd37d916faad372302559d3615bab6f911a770564ee4eaa933255ced4cfba305bec32399dcf3206498b5d9
@@ -41,7 +41,7 @@ module Hisui
41
41
  )
42
42
 
43
43
  response = reporting_service.batch_get_reports(request)
44
- Hisui::Response.new(response)
44
+ Hisui::Response.new(response: response, request: self)
45
45
  end
46
46
  end
47
47
  end
@@ -1,7 +1,7 @@
1
1
  module Hisui
2
2
  class Response
3
- def initialize(response)
4
- @ga_data = GaData.new(response)
3
+ def initialize(response:, request:)
4
+ @ga_data = GaData.new(response: response, request: request)
5
5
  end
6
6
 
7
7
  def raw_attributes
@@ -1,16 +1,20 @@
1
1
  module Hisui
2
2
  class Response
3
3
  class GaData
4
- attr_reader :response
4
+ attr_reader :response, :date_ranges
5
5
 
6
- def initialize(response)
6
+ DATE_DIMENSIONS = %w[ga:date ga:dateHour ga:dateHourMinute].freeze
7
+
8
+ def initialize(response:, request:)
7
9
  @response = response
10
+ @date_ranges = [Range.new(request.start_date.beginning_of_day, request.end_date.end_of_day), Range.new(request.try(:comparing_start_date).try(:beginning_of_day), request.try(:comparing_end_date).try(:end_of_day))]
8
11
  end
9
12
 
10
13
  def construct(ordinal)
11
14
  row_data_struct = Struct.new(*fields)
12
15
 
13
16
  data.try(:rows).try(:each_with_object, []) do |row, arr|
17
+ next if date_indices.present? && date_indices.all? { |index| date_ranges.try(ordinal.to_sym).exclude?(row.dimensions[index].in_time_zone) }
14
18
  row_data = []
15
19
  row.dimensions.each do |dimension|
16
20
  row_data << dimension
@@ -97,6 +101,18 @@ module Hisui
97
101
  end
98
102
  end
99
103
 
104
+ # NOTE: When dimensions include DATE_DIMENSIONS, Google Analytics data has data to include primary and comparing date range.
105
+ # This is a method to filter only primary or comparing data.
106
+ def date_indices
107
+ @date_indices ||= begin
108
+ used_date_dimensions = DATE_DIMENSIONS & column_header.dimensions
109
+
110
+ used_date_dimensions.each_with_object([]) do |dimension, arr|
111
+ arr << column_header.dimensions.index(dimension)
112
+ end
113
+ end
114
+ end
115
+
100
116
  def data
101
117
  @data ||= response.reports.first.data
102
118
  end
@@ -1,3 +1,3 @@
1
1
  module Hisui
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hisui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - ikepon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-19 00:00:00.000000000 Z
11
+ date: 2018-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails