Class: AmazonCompetitor
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- AmazonCompetitor
- Defined in:
- app/models/amazon_competitor.rb
Overview
== Schema Information
Table name: amazon_competitors
Database name: primary
id :bigint not null, primary key
name :string
notes :text
created_at :datetime not null
updated_at :datetime not null
seller_id :string
Indexes
index_amazon_competitors_on_seller_id (seller_id) UNIQUE
Constant Summary
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
Class Method Summary collapse
-
.name_for(seller_id) ⇒ String
Look up competitor name by seller ID.
-
.named ⇒ ActiveRecord::Relation<AmazonCompetitor>
A relation of AmazonCompetitors that are named.
-
.named?(seller_id) ⇒ Boolean
Check if a seller ID is named (has a known name in the database).
-
.storefront_url(seller_id, marketplace: 'amazon.com') ⇒ String
Get storefront URL for a seller.
-
.unnamed ⇒ ActiveRecord::Relation<AmazonCompetitor>
A relation of AmazonCompetitors that are unnamed.
Instance Method Summary collapse
-
#display_name ⇒ Object
Display name (name or seller ID if unnamed).
- #storefront_url(marketplace: 'amazon.com') ⇒ String
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#seller_id ⇒ String
22 |
# File 'app/models/amazon_competitor.rb', line 22 validates :seller_id, presence: true, uniqueness: true |
Class Method Details
.name_for(seller_id) ⇒ String
Look up competitor name by seller ID.
Returns the name if found, otherwise returns the raw seller ID.
33 34 35 36 37 38 |
# File 'app/models/amazon_competitor.rb', line 33 def self.name_for(seller_id) return seller_id if seller_id.blank? competitor = find_by(seller_id: seller_id) competitor&.name.presence || seller_id end |
.named ⇒ ActiveRecord::Relation<AmazonCompetitor>
A relation of AmazonCompetitors that are named. Active Record Scope
26 |
# File 'app/models/amazon_competitor.rb', line 26 scope :named, -> { where.not(name: [nil, '']) } |
.named?(seller_id) ⇒ Boolean
Check if a seller ID is named (has a known name in the database).
43 44 45 46 47 |
# File 'app/models/amazon_competitor.rb', line 43 def self.named?(seller_id) return false if seller_id.blank? named.exists?(seller_id: seller_id) end |
.storefront_url(seller_id, marketplace: 'amazon.com') ⇒ String
Get storefront URL for a seller.
53 54 55 |
# File 'app/models/amazon_competitor.rb', line 53 def self.storefront_url(seller_id, marketplace: 'amazon.com') "https://www.#{marketplace}/sp?seller=#{seller_id}" end |
.unnamed ⇒ ActiveRecord::Relation<AmazonCompetitor>
A relation of AmazonCompetitors that are unnamed. Active Record Scope
27 |
# File 'app/models/amazon_competitor.rb', line 27 scope :unnamed, -> { where(name: [nil, '']) } |
Instance Method Details
#display_name ⇒ Object
Display name (name or seller ID if unnamed)
64 65 66 |
# File 'app/models/amazon_competitor.rb', line 64 def display_name name.presence || seller_id end |
#storefront_url(marketplace: 'amazon.com') ⇒ String
59 60 61 |
# File 'app/models/amazon_competitor.rb', line 59 def storefront_url(marketplace: 'amazon.com') self.class.storefront_url(seller_id, marketplace: marketplace) end |