Class: Rerout::Models::ProjectStats

Inherits:
Object
  • Object
show all
Defined in:
lib/rerout/models.rb

Overview

Project-wide aggregate stats response.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attrs) ⇒ ProjectStats

Returns a new instance of ProjectStats.



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rerout/models.rb', line 162

def initialize(**attrs)
  @days = attrs[:days]
  @total_clicks = attrs[:total_clicks]
  @qr_scans = attrs[:qr_scans]
  @daily = attrs[:daily].freeze
  @countries = attrs[:countries].freeze
  @referrers = attrs[:referrers].freeze
  @devices = attrs[:devices].freeze
  @browsers = attrs[:browsers].freeze
  @top_codes = attrs[:top_codes].freeze
  freeze
end

Instance Attribute Details

#browsersObject (readonly)

Returns the value of attribute browsers.



159
160
161
# File 'lib/rerout/models.rb', line 159

def browsers
  @browsers
end

#countriesObject (readonly)

Returns the value of attribute countries.



159
160
161
# File 'lib/rerout/models.rb', line 159

def countries
  @countries
end

#dailyObject (readonly)

Returns the value of attribute daily.



159
160
161
# File 'lib/rerout/models.rb', line 159

def daily
  @daily
end

#daysObject (readonly)

Returns the value of attribute days.



159
160
161
# File 'lib/rerout/models.rb', line 159

def days
  @days
end

#devicesObject (readonly)

Returns the value of attribute devices.



159
160
161
# File 'lib/rerout/models.rb', line 159

def devices
  @devices
end

#qr_scansObject (readonly)

Returns the value of attribute qr_scans.



159
160
161
# File 'lib/rerout/models.rb', line 159

def qr_scans
  @qr_scans
end

#referrersObject (readonly)

Returns the value of attribute referrers.



159
160
161
# File 'lib/rerout/models.rb', line 159

def referrers
  @referrers
end

#top_codesObject (readonly)

Returns the value of attribute top_codes.



159
160
161
# File 'lib/rerout/models.rb', line 159

def top_codes
  @top_codes
end

#total_clicksObject (readonly)

Returns the value of attribute total_clicks.



159
160
161
# File 'lib/rerout/models.rb', line 159

def total_clicks
  @total_clicks
end

Class Method Details

.from_hash(hash) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/rerout/models.rb', line 175

def self.from_hash(hash)
  new(
    days: hash['days'],
    total_clicks: hash['total_clicks'],
    qr_scans: hash['qr_scans'],
    daily: (hash['daily'] || []).map { |d| DailyClicksPoint.from_hash(d) },
    countries: (hash['countries'] || []).map { |b| StatsBreakdown.from_hash(b) },
    referrers: (hash['referrers'] || []).map { |b| StatsBreakdown.from_hash(b) },
    devices: (hash['devices'] || []).map { |b| StatsBreakdown.from_hash(b) },
    browsers: (hash['browsers'] || []).map { |b| StatsBreakdown.from_hash(b) },
    top_codes: (hash['top_codes'] || []).map { |b| StatsBreakdown.from_hash(b) }
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



201
202
203
# File 'lib/rerout/models.rb', line 201

def ==(other)
  other.is_a?(ProjectStats) && other.to_h == to_h
end

#hashObject



206
207
208
# File 'lib/rerout/models.rb', line 206

def hash
  to_h.hash
end

#to_hObject



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/rerout/models.rb', line 189

def to_h
  {
    days: days, total_clicks: total_clicks, qr_scans: qr_scans,
    daily: daily.map(&:to_h),
    countries: countries.map(&:to_h),
    referrers: referrers.map(&:to_h),
    devices: devices.map(&:to_h),
    browsers: browsers.map(&:to_h),
    top_codes: top_codes.map(&:to_h)
  }
end