Class: Rerout::Models::LinkStats

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

Overview

Per-link click stats response.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, days:, total_clicks:, qr_scans:, countries:, referrers:) ⇒ LinkStats

Returns a new instance of LinkStats.



312
313
314
315
316
317
318
319
320
# File 'lib/rerout/models.rb', line 312

def initialize(code:, days:, total_clicks:, qr_scans:, countries:, referrers:)
  @code = code
  @days = days
  @total_clicks = total_clicks
  @qr_scans = qr_scans
  @countries = countries.freeze
  @referrers = referrers.freeze
  freeze
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



310
311
312
# File 'lib/rerout/models.rb', line 310

def code
  @code
end

#countriesObject (readonly)

Returns the value of attribute countries.



310
311
312
# File 'lib/rerout/models.rb', line 310

def countries
  @countries
end

#daysObject (readonly)

Returns the value of attribute days.



310
311
312
# File 'lib/rerout/models.rb', line 310

def days
  @days
end

#qr_scansObject (readonly)

Returns the value of attribute qr_scans.



310
311
312
# File 'lib/rerout/models.rb', line 310

def qr_scans
  @qr_scans
end

#referrersObject (readonly)

Returns the value of attribute referrers.



310
311
312
# File 'lib/rerout/models.rb', line 310

def referrers
  @referrers
end

#total_clicksObject (readonly)

Returns the value of attribute total_clicks.



310
311
312
# File 'lib/rerout/models.rb', line 310

def total_clicks
  @total_clicks
end

Class Method Details

.from_hash(hash) ⇒ Object



322
323
324
325
326
327
328
329
330
331
# File 'lib/rerout/models.rb', line 322

def self.from_hash(hash)
  new(
    code: hash['code'],
    days: hash['days'],
    total_clicks: hash['total_clicks'],
    qr_scans: hash['qr_scans'],
    countries: (hash['countries'] || []).map { |c| StatsBreakdown.from_hash(c) },
    referrers: (hash['referrers'] || []).map { |c| StatsBreakdown.from_hash(c) }
  )
end

Instance Method Details

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



340
341
342
# File 'lib/rerout/models.rb', line 340

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

#hashObject



345
346
347
# File 'lib/rerout/models.rb', line 345

def hash
  to_h.hash
end

#to_hObject



333
334
335
336
337
338
# File 'lib/rerout/models.rb', line 333

def to_h
  {
    code: code, days: days, total_clicks: total_clicks, qr_scans: qr_scans,
    countries: countries.map(&:to_h), referrers: referrers.map(&:to_h)
  }
end