Class: SerpCheap::Ad

Inherits:
Object
  • Object
show all
Defined in:
lib/serpcheap/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position:, title:, link:, block:, displayed_link: nil, snippet: nil, sitelinks: nil) ⇒ Ad

Returns a new instance of Ad.



53
54
55
56
57
58
59
60
61
# File 'lib/serpcheap/models.rb', line 53

def initialize(position:, title:, link:, block:, displayed_link: nil, snippet: nil, sitelinks: nil)
  @position = position
  @title = title
  @link = link
  @block = block
  @displayed_link = displayed_link
  @snippet = snippet
  @sitelinks = sitelinks
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



51
52
53
# File 'lib/serpcheap/models.rb', line 51

def block
  @block
end

Returns the value of attribute displayed_link.



51
52
53
# File 'lib/serpcheap/models.rb', line 51

def displayed_link
  @displayed_link
end

Returns the value of attribute link.



51
52
53
# File 'lib/serpcheap/models.rb', line 51

def link
  @link
end

#positionObject (readonly)

Returns the value of attribute position.



51
52
53
# File 'lib/serpcheap/models.rb', line 51

def position
  @position
end

Returns the value of attribute sitelinks.



51
52
53
# File 'lib/serpcheap/models.rb', line 51

def sitelinks
  @sitelinks
end

#snippetObject (readonly)

Returns the value of attribute snippet.



51
52
53
# File 'lib/serpcheap/models.rb', line 51

def snippet
  @snippet
end

#titleObject (readonly)

Returns the value of attribute title.



51
52
53
# File 'lib/serpcheap/models.rb', line 51

def title
  @title
end

Class Method Details

.from_hash(d) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/serpcheap/models.rb', line 63

def self.from_hash(d)
  sl = d["sitelinks"]
  new(
    position: d["position"].to_i,
    title: d["title"].to_s,
    link: d["link"].to_s,
    block: d["block"].to_s,
    displayed_link: d["displayedLink"],
    snippet: d["snippet"],
    sitelinks: sl.is_a?(Array) ? sl.map { |s| Sitelink.from_hash(s) } : nil
  )
end