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.



153
154
155
156
157
158
159
160
161
# File 'lib/rerout/models.rb', line 153

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.



151
152
153
# File 'lib/rerout/models.rb', line 151

def code
  @code
end

#countriesObject (readonly)

Returns the value of attribute countries.



151
152
153
# File 'lib/rerout/models.rb', line 151

def countries
  @countries
end

#daysObject (readonly)

Returns the value of attribute days.



151
152
153
# File 'lib/rerout/models.rb', line 151

def days
  @days
end

#qr_scansObject (readonly)

Returns the value of attribute qr_scans.



151
152
153
# File 'lib/rerout/models.rb', line 151

def qr_scans
  @qr_scans
end

#referrersObject (readonly)

Returns the value of attribute referrers.



151
152
153
# File 'lib/rerout/models.rb', line 151

def referrers
  @referrers
end

#total_clicksObject (readonly)

Returns the value of attribute total_clicks.



151
152
153
# File 'lib/rerout/models.rb', line 151

def total_clicks
  @total_clicks
end

Class Method Details

.from_hash(hash) ⇒ Object



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

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?



181
182
183
# File 'lib/rerout/models.rb', line 181

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

#hashObject



186
187
188
# File 'lib/rerout/models.rb', line 186

def hash
  to_h.hash
end

#to_hObject



174
175
176
177
178
179
# File 'lib/rerout/models.rb', line 174

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