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.



119
120
121
122
123
124
125
126
127
# File 'lib/rerout/models.rb', line 119

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.



117
118
119
# File 'lib/rerout/models.rb', line 117

def code
  @code
end

#countriesObject (readonly)

Returns the value of attribute countries.



117
118
119
# File 'lib/rerout/models.rb', line 117

def countries
  @countries
end

#daysObject (readonly)

Returns the value of attribute days.



117
118
119
# File 'lib/rerout/models.rb', line 117

def days
  @days
end

#qr_scansObject (readonly)

Returns the value of attribute qr_scans.



117
118
119
# File 'lib/rerout/models.rb', line 117

def qr_scans
  @qr_scans
end

#referrersObject (readonly)

Returns the value of attribute referrers.



117
118
119
# File 'lib/rerout/models.rb', line 117

def referrers
  @referrers
end

#total_clicksObject (readonly)

Returns the value of attribute total_clicks.



117
118
119
# File 'lib/rerout/models.rb', line 117

def total_clicks
  @total_clicks
end

Class Method Details

.from_hash(hash) ⇒ Object



129
130
131
132
133
134
135
136
137
138
# File 'lib/rerout/models.rb', line 129

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?



147
148
149
# File 'lib/rerout/models.rb', line 147

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

#hashObject



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

def hash
  to_h.hash
end

#to_hObject



140
141
142
143
144
145
# File 'lib/rerout/models.rb', line 140

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