Class: GScraper::SponsoredAd

Inherits:
Object
  • Object
show all
Defined in:
lib/gscraper/sponsored_ad.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, url) ⇒ SponsoredAd

Creates a new SponsoredAd.

Parameters:

  • title (String)

    The title of the ad.

  • url (URI::HTTP)

    The URL of the ad.



41
42
43
44
# File 'lib/gscraper/sponsored_ad.rb', line 41

def initialize(title,url)
  @title = title
  @url   = url
end

Instance Attribute Details

#titleObject (readonly)

Title of the ad



27
28
29
# File 'lib/gscraper/sponsored_ad.rb', line 27

def title
  @title
end

#urlObject (readonly)

URL of the ad



30
31
32
# File 'lib/gscraper/sponsored_ad.rb', line 30

def url
  @url
end

Instance Method Details

The direct link of the ad.

Returns:

  • (String)

    The direct link.



52
53
54
# File 'lib/gscraper/sponsored_ad.rb', line 52

def direct_link
  @url.query_params['adurl'] || @url.query_params['q']
end

#direct_urlURI::HTTP

The direct URI of the ad.

Returns:

  • (URI::HTTP)

    The direct URI.



62
63
64
# File 'lib/gscraper/sponsored_ad.rb', line 62

def direct_url
  URI(URI.escape(direct_link))
end

#to_sString

The title of the ad.

Returns:

  • (String)

    The title.



72
73
74
# File 'lib/gscraper/sponsored_ad.rb', line 72

def to_s
  @title.to_s
end