Class: Source
- Inherits:
-
Object
show all
- Defined in:
- lib/sources/source.rb
Defined Under Namespace
Classes: GeneralError, ProductFatalError, ProductNotFoundError
Constant Summary
collapse
- SIMPLE_SOURCES_YAML_FILE =
File.join(File.dirname(__FILE__), 'simple_sources.yml')
- @@subclasses =
[]
- @@sources =
Set.new
- @@sources_map =
{}
- @@offer_sources =
[]
- @@affiliate_sources =
[]
- @@merchant_rating_sources =
[]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ Source
Returns a new instance of Source.
85
86
87
|
# File 'lib/sources/source.rb', line 85
def initialize(attributes)
attributes.each {|k, v| instance_variable_set("@#{k}", v)}
end
|
Instance Attribute Details
#batch_fetch_delay ⇒ Object
Returns the value of attribute batch_fetch_delay.
42
43
44
|
# File 'lib/sources/source.rb', line 42
def batch_fetch_delay
@batch_fetch_delay
end
|
#cpc ⇒ Object
Returns the value of attribute cpc.
31
32
33
|
# File 'lib/sources/source.rb', line 31
def cpc
@cpc
end
|
#for_product_info ⇒ Object
Returns the value of attribute for_product_info.
49
50
51
|
# File 'lib/sources/source.rb', line 49
def for_product_info
@for_product_info
end
|
#for_review_aggregates ⇒ Object
Returns the value of attribute for_review_aggregates.
50
51
52
|
# File 'lib/sources/source.rb', line 50
def for_review_aggregates
@for_review_aggregates
end
|
#homepage ⇒ Object
Returns the value of attribute homepage.
30
31
32
|
# File 'lib/sources/source.rb', line 30
def homepage
@homepage
end
|
#mappable ⇒ Object
properties from the legacy Source table in DA/DCHQ
48
49
50
|
# File 'lib/sources/source.rb', line 48
def mappable
@mappable
end
|
#name ⇒ Object
Returns the value of attribute name.
29
30
31
|
# File 'lib/sources/source.rb', line 29
def name
@name
end
|
#offer_affiliate ⇒ Object
Also known as:
offer_affiliate?
Returns the value of attribute offer_affiliate.
38
39
40
|
# File 'lib/sources/source.rb', line 38
def offer_affiliate
@offer_affiliate
end
|
#offer_enabled ⇒ Object
Also known as:
offer_enabled?, for_offers
Returns the value of attribute offer_enabled.
32
33
34
|
# File 'lib/sources/source.rb', line 32
def offer_enabled
@offer_enabled
end
|
#offer_ttl_seconds ⇒ Object
Returns the value of attribute offer_ttl_seconds.
35
36
37
|
# File 'lib/sources/source.rb', line 35
def offer_ttl_seconds
@offer_ttl_seconds
end
|
#product_code_examples ⇒ Object
Returns the value of attribute product_code_examples.
44
45
46
|
# File 'lib/sources/source.rb', line 44
def product_code_examples
@product_code_examples
end
|
#product_code_regexp ⇒ Object
Returns the value of attribute product_code_regexp.
43
44
45
|
# File 'lib/sources/source.rb', line 43
def product_code_regexp
@product_code_regexp
end
|
#product_page_link_erb ⇒ Object
Returns the value of attribute product_page_link_erb.
45
46
47
|
# File 'lib/sources/source.rb', line 45
def product_page_link_erb
@product_page_link_erb
end
|
#search_token_separator ⇒ Object
Returns the value of attribute search_token_separator.
52
53
54
|
# File 'lib/sources/source.rb', line 52
def search_token_separator
@search_token_separator
end
|
#search_url ⇒ Object
Returns the value of attribute search_url.
51
52
53
|
# File 'lib/sources/source.rb', line 51
def search_url
@search_url
end
|
#supports_lifetime_ratings ⇒ Object
Also known as:
supports_lifetime_ratings?
Returns the value of attribute supports_lifetime_ratings.
40
41
42
|
# File 'lib/sources/source.rb', line 40
def supports_lifetime_ratings
@supports_lifetime_ratings
end
|
#use_for_merchant_ratings ⇒ Object
Also known as:
use_for_merchant_ratings?
Returns the value of attribute use_for_merchant_ratings.
36
37
38
|
# File 'lib/sources/source.rb', line 36
def use_for_merchant_ratings
@use_for_merchant_ratings
end
|
Class Method Details
.affiliate_sources ⇒ Object
111
112
113
114
115
116
117
|
# File 'lib/sources/source.rb', line 111
def self.affiliate_sources
load_sources
if @@affiliate_sources.empty?
@@affiliate_sources = @@sources.select{|source| source.offer_affiliate?}
end
@@affiliate_sources
end
|
.inherited(child) ⇒ Object
79
80
81
82
83
|
# File 'lib/sources/source.rb', line 79
def self.inherited(child)
@@subclasses << child
set_source_keyname_const(child.keyname)
super
end
|
.keyname ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/sources/source.rb', line 67
def self.keyname
if @keyname.nil? && !self.name.nil?
matches = self.name.match(/(.+)Source/)
@keyname = matches[1].gsub(/([a-z\d])([A-Z])/,'\1-\2').downcase unless matches.nil?
end
@keyname
end
|
.keyname=(keyname) ⇒ Object
75
76
77
|
# File 'lib/sources/source.rb', line 75
def self.keyname=(keyname)
@keyname = keyname
end
|
.merchant_rating_sources ⇒ Object
119
120
121
122
123
124
125
|
# File 'lib/sources/source.rb', line 119
def self.merchant_rating_sources
load_sources
if @@merchant_rating_sources.empty?
@@merchant_rating_sources = @@sources.select{|source| source.use_for_merchant_ratings?}
end
@@merchant_rating_sources
end
|
.method_missing(meth) ⇒ Object
127
128
129
130
131
132
133
134
|
# File 'lib/sources/source.rb', line 127
def self.method_missing(meth)
source = nil
if matches = meth.to_s.match(/(.+)_source$/)
source_keyname = matches[1].gsub('_', '-')
source = send(:source, source_keyname)
end
source.nil? ? super : source
end
|
.offer_sources ⇒ Object
103
104
105
106
107
108
109
|
# File 'lib/sources/source.rb', line 103
def self.offer_sources
load_sources
if @@offer_sources.empty?
@@offer_sources = @@sources.select{|source| source.offer_enabled?}
end
@@offer_sources
end
|
.source(source_keyname) ⇒ Object
93
94
95
96
|
# File 'lib/sources/source.rb', line 93
def self.source(source_keyname)
load_sources
@@sources_map[source_keyname]
end
|
.sources ⇒ Object
98
99
100
101
|
# File 'lib/sources/source.rb', line 98
def self.sources
load_sources
@@sources
end
|
Instance Method Details
#code_from_merchant_source_page_url(merchant_source_page_url) ⇒ Object
152
153
154
|
# File 'lib/sources/source.rb', line 152
def code_from_merchant_source_page_url(merchant_source_page_url)
nil
end
|
#eql?(other) ⇒ Boolean
176
177
178
|
# File 'lib/sources/source.rb', line 176
def eql?(other)
self.class == other.class
end
|
#fetch_merchant_source(merchant_source_page_url) ⇒ Object
156
157
158
|
# File 'lib/sources/source.rb', line 156
def fetch_merchant_source(merchant_source_page_url)
nil
end
|
#fetch_offers(product_code) ⇒ Object
168
169
170
|
# File 'lib/sources/source.rb', line 168
def fetch_offers(product_code)
nil
end
|
160
161
162
|
# File 'lib/sources/source.rb', line 160
def format_rating(merchant_source)
"#{merchant_source.get_merchant_rating}%"
end
|
#hash ⇒ Object
172
173
174
|
# File 'lib/sources/source.rb', line 172
def hash
self.class.hash
end
|
#keyname ⇒ Object
89
90
91
|
# File 'lib/sources/source.rb', line 89
def keyname
self.class.keyname
end
|
#nullify_offer_url(offer_url) ⇒ Object
164
165
166
|
# File 'lib/sources/source.rb', line 164
def nullify_offer_url(offer_url)
offer_url
end
|
#product_code_valid?(product_code) ⇒ Boolean
136
137
138
|
# File 'lib/sources/source.rb', line 136
def product_code_valid?(product_code)
product_code_regexp.nil? ? (!product_code.nil? && product_code.length > 0) : !(product_code =~ product_code_regexp).nil?
end
|
#product_page_link(product_code) ⇒ Object
140
141
142
|
# File 'lib/sources/source.rb', line 140
def product_page_link(product_code)
ERB.new(product_page_link_erb).result(binding) unless product_page_link_erb.nil?
end
|
#to_s ⇒ Object
180
181
182
|
# File 'lib/sources/source.rb', line 180
def to_s
keyname
end
|
#url_for_merchant_source_page(merchant_source_code) ⇒ Object
144
145
146
|
# File 'lib/sources/source.rb', line 144
def url_for_merchant_source_page(merchant_source_code)
nil
end
|
#url_for_merchant_source_page_alt(merchant_source_alt_code) ⇒ Object
148
149
150
|
# File 'lib/sources/source.rb', line 148
def url_for_merchant_source_page_alt(merchant_source_alt_code)
nil
end
|