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
Instance Attribute Summary collapse
- #seller_id ⇒ Object readonly
Class Method Summary collapse
-
.name_for(seller_id) ⇒ Object
Look up competitor name by seller ID Returns the name if found, otherwise returns the raw 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') ⇒ Object
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') ⇒ Object
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#seller_id ⇒ Object (readonly)
19 |
# File 'app/models/amazon_competitor.rb', line 19 validates :seller_id, presence: true, uniqueness: true |
Class Method Details
.name_for(seller_id) ⇒ Object
Look up competitor name by seller ID
Returns the name if found, otherwise returns the raw seller ID
28 29 30 31 32 33 |
# File 'app/models/amazon_competitor.rb', line 28 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
23 |
# File 'app/models/amazon_competitor.rb', line 23 scope :named, -> { where.not(name: [nil, '']) } |
.named?(seller_id) ⇒ Boolean
Check if a seller ID is named (has a known name in the database)
36 37 38 39 40 |
# File 'app/models/amazon_competitor.rb', line 36 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') ⇒ Object
Get storefront URL for a seller
43 44 45 |
# File 'app/models/amazon_competitor.rb', line 43 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
24 |
# File 'app/models/amazon_competitor.rb', line 24 scope :unnamed, -> { where(name: [nil, '']) } |
Instance Method Details
#display_name ⇒ Object
Display name (name or seller ID if unnamed)
52 53 54 |
# File 'app/models/amazon_competitor.rb', line 52 def display_name name.presence || seller_id end |
#storefront_url(marketplace: 'amazon.com') ⇒ Object
47 48 49 |
# File 'app/models/amazon_competitor.rb', line 47 def storefront_url(marketplace: 'amazon.com') self.class.storefront_url(seller_id, marketplace: marketplace) end |