Class: GScraper::SponsoredLinks
- Inherits:
-
Array
- Object
- Array
- GScraper::SponsoredLinks
- Defined in:
- lib/gscraper/sponsored_links.rb
Instance Method Summary collapse
-
#ads_with_direct_url(direct_url) {|ad| ... } ⇒ Array, Enumerator
Selects the ads with the matching direct URL.
-
#ads_with_title(title) {|ad| ... } ⇒ Array, Enumerator
Selects the ads with the matching title.
-
#ads_with_url(url) {|ad| ... } ⇒ Array, Enumerator
Selects the ads with the matching URL.
-
#direct_urls ⇒ Array<URI::HTTP>
The direct URLs for the ads.
-
#direct_urls_of {|ad| ... } ⇒ Array<String>
The direct URLs of the selected ads.
-
#each_direct_url {|direct_url| ... } ⇒ Enumerator
Iterates over the direct URLs of each ad.
-
#each_title {|title| ... } ⇒ Enumerator
Iterates over the titles of each ad.
-
#each_url {|url| ... } ⇒ Enumerator
Iterates over the URLs of each ad.
-
#initialize(ads = []) {|links| ... } ⇒ SponsoredLinks
constructor
Creates a new SponsoredLinks object.
-
#map {|ad| ... } ⇒ Array, Enumerator
Maps the sponsored ads.
-
#select {|ad| ... } ⇒ Array, Enumerator
(also: #ads_with)
Selects the ads within the sponsored links.
-
#titles ⇒ Array<String>
The titles for the ads.
-
#titles_of {|ad| ... } ⇒ Array<String>
The titles of the selected ads.
-
#urls ⇒ Array<URI::HTTP>
The URLs for the ads.
-
#urls_of {|ad| ... } ⇒ Array<String>
The URLs of the selected ads.
Constructor Details
#initialize(ads = []) {|links| ... } ⇒ SponsoredLinks
Creates a new SponsoredLinks object.
39 40 41 42 43 |
# File 'lib/gscraper/sponsored_links.rb', line 39 def initialize(ads=[]) super(ads) yield self if block_given? end |
Instance Method Details
#ads_with_direct_url(direct_url) {|ad| ... } ⇒ Array, Enumerator
Selects the ads with the matching direct URL.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/gscraper/sponsored_links.rb', line 202 def ads_with_direct_url(direct_url) return enum_for(:ads_with_direct_url,direct_url) unless block_given? comparitor = if direct_url.kind_of?(Regexp) lambda { |ad| ad.direct_url =~ direct_url } else lambda { |ad| ad.direct_url == direct_url } end return ads_with do |ad| if comparitor.call(ad) yield ad true end end end |
#ads_with_title(title) {|ad| ... } ⇒ Array, Enumerator
Selects the ads with the matching title.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/gscraper/sponsored_links.rb', line 126 def ads_with_title(title) return enum_for(:ads_with_title,title) unless block_given? comparitor = if title.kind_of?(Regexp) lambda { |ad| ad.title =~ title } else lambda { |ad| ad.title == title } end return ads_with do |ad| if comparitor.call(ad) yield ad true end end end |
#ads_with_url(url) {|ad| ... } ⇒ Array, Enumerator
Selects the ads with the matching URL.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/gscraper/sponsored_links.rb', line 164 def ads_with_url(url) return enum_for(:ads_with_url,url) unless block_given? comparitor = if url.kind_of?(Regexp) lambda { |ad| ad.url =~ url } else lambda { |ad| ad.url == url } end return ads_with do |ad| if comparitor.call(ad) yield ad true end end end |
#direct_urls ⇒ Array<URI::HTTP>
The direct URLs for the ads.
324 325 326 |
# File 'lib/gscraper/sponsored_links.rb', line 324 def direct_urls each_direct_url.to_a end |
#direct_urls_of {|ad| ... } ⇒ Array<String>
The direct URLs of the selected ads.
381 382 383 |
# File 'lib/gscraper/sponsored_links.rb', line 381 def direct_urls_of(&block) ads_with(&block).direct_urls end |
#each_direct_url {|direct_url| ... } ⇒ Enumerator
Iterates over the direct URLs of each ad.
281 282 283 284 285 286 287 |
# File 'lib/gscraper/sponsored_links.rb', line 281 def each_direct_url unless block_given? enum_for(:each_direct_url) else each { |ad| yield ad.direct_url } end end |
#each_title {|title| ... } ⇒ Enumerator
Iterates over the titles of each ad.
235 236 237 238 239 240 241 |
# File 'lib/gscraper/sponsored_links.rb', line 235 def each_title unless block_given? enum_for(:each_title) else each { |ad| yield ad.title } end end |
#each_url {|url| ... } ⇒ Enumerator
Iterates over the URLs of each ad.
258 259 260 261 262 263 264 |
# File 'lib/gscraper/sponsored_links.rb', line 258 def each_url unless block_given? enum_for(:each_url) else each { |ad| yield ad.url } end end |
#map {|ad| ... } ⇒ Array, Enumerator
Maps the sponsored ads.
66 67 68 69 70 71 72 73 |
# File 'lib/gscraper/sponsored_links.rb', line 66 def map return enum_for(:map) unless block_given? mapped = [] each { |ad| mapped << yield(ad) } return mapped end |
#select {|ad| ... } ⇒ Array, Enumerator Also known as: ads_with
Selects the ads within the sponsored links.
91 92 93 94 95 96 97 |
# File 'lib/gscraper/sponsored_links.rb', line 91 def select(&block) unless block enum_for(:select) else SponsoredLinks.new(super(&block)) end end |
#titles ⇒ Array<String>
The titles for the ads.
298 299 300 |
# File 'lib/gscraper/sponsored_links.rb', line 298 def titles each_title.to_a end |
#titles_of {|ad| ... } ⇒ Array<String>
The titles of the selected ads.
343 344 345 |
# File 'lib/gscraper/sponsored_links.rb', line 343 def titles_of(&block) ads_with(&block).titles end |
#urls ⇒ Array<URI::HTTP>
The URLs for the ads.
311 312 313 |
# File 'lib/gscraper/sponsored_links.rb', line 311 def urls each_url.to_a end |
#urls_of {|ad| ... } ⇒ Array<String>
The URLs of the selected ads.
362 363 364 |
# File 'lib/gscraper/sponsored_links.rb', line 362 def urls_of(&block) ads_with(&block).urls end |