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.



355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/rerout/models.rb', line 355

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.



352
353
354
# File 'lib/rerout/models.rb', line 352

def browsers
  @browsers
end

#countriesObject (readonly)

Returns the value of attribute countries.



352
353
354
# File 'lib/rerout/models.rb', line 352

def countries
  @countries
end

#dailyObject (readonly)

Returns the value of attribute daily.



352
353
354
# File 'lib/rerout/models.rb', line 352

def daily
  @daily
end

#daysObject (readonly)

Returns the value of attribute days.



352
353
354
# File 'lib/rerout/models.rb', line 352

def days
  @days
end

#devicesObject (readonly)

Returns the value of attribute devices.



352
353
354
# File 'lib/rerout/models.rb', line 352

def devices
  @devices
end

#qr_scansObject (readonly)

Returns the value of attribute qr_scans.



352
353
354
# File 'lib/rerout/models.rb', line 352

def qr_scans
  @qr_scans
end

#referrersObject (readonly)

Returns the value of attribute referrers.



352
353
354
# File 'lib/rerout/models.rb', line 352

def referrers
  @referrers
end

#top_codesObject (readonly)

Returns the value of attribute top_codes.



352
353
354
# File 'lib/rerout/models.rb', line 352

def top_codes
  @top_codes
end

#total_clicksObject (readonly)

Returns the value of attribute total_clicks.



352
353
354
# File 'lib/rerout/models.rb', line 352

def total_clicks
  @total_clicks
end

Class Method Details

.from_hash(hash) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/rerout/models.rb', line 368

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?



394
395
396
# File 'lib/rerout/models.rb', line 394

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

#hashObject



399
400
401
# File 'lib/rerout/models.rb', line 399

def hash
  to_h.hash
end

#to_hObject



382
383
384
385
386
387
388
389
390
391
392
# File 'lib/rerout/models.rb', line 382

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