Class: Rerout::Models::Link
- Inherits:
-
Object
- Object
- Rerout::Models::Link
- Defined in:
- lib/rerout/models.rb
Overview
A short link.
Constant Summary collapse
- ATTRS =
%i[ code short_url domain_hostname target_url project_id expires_at is_active seo_title seo_description seo_image_url seo_canonical_url seo_noindex seo_updated_at tags created_at updated_at ].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(**attrs) ⇒ Link
constructor
A new instance of Link.
- #to_h ⇒ Object
Constructor Details
Class Method Details
.from_hash(hash) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rerout/models.rb', line 54 def self.from_hash(hash) new( code: hash['code'], short_url: hash['short_url'], domain_hostname: hash['domain_hostname'], target_url: hash['target_url'], project_id: hash['project_id'], expires_at: hash['expires_at'], is_active: hash['is_active'], seo_title: hash['seo_title'], seo_description: hash['seo_description'], seo_image_url: hash['seo_image_url'], seo_canonical_url: hash['seo_canonical_url'], seo_noindex: hash.fetch('seo_noindex', true), seo_updated_at: hash['seo_updated_at'], tags: (hash['tags'] || []).map { |t| Tag.from_hash(t) }, created_at: hash['created_at'], updated_at: hash['updated_at'] ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
81 82 83 |
# File 'lib/rerout/models.rb', line 81 def ==(other) other.is_a?(Link) && other.to_h == to_h end |
#hash ⇒ Object
86 87 88 |
# File 'lib/rerout/models.rb', line 86 def hash to_h.hash end |
#to_h ⇒ Object
75 76 77 78 79 |
# File 'lib/rerout/models.rb', line 75 def to_h ATTRS.to_h do |k| [k, k == :tags ? .map(&:to_h) : public_send(k)] end end |