Class: SerpCheap::OrganicResult

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:, snippet:, date: nil, sitelinks: nil, content: nil, screenshot_url: nil, scrape_error: nil) ⇒ OrganicResult

Returns a new instance of OrganicResult.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/serpcheap/models.rb', line 21

def initialize(position:, title:, link:, snippet:, date: nil, sitelinks: nil,
               content: nil, screenshot_url: nil, scrape_error: nil)
  @position = position
  @title = title
  @link = link
  @snippet = snippet
  @date = date
  @sitelinks = sitelinks
  @content = content
  @screenshot_url = screenshot_url
  @scrape_error = scrape_error
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def content
  @content
end

#dateObject (readonly)

Returns the value of attribute date.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def date
  @date
end

Returns the value of attribute link.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def link
  @link
end

#positionObject (readonly)

Returns the value of attribute position.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def position
  @position
end

#scrape_errorObject (readonly)

Returns the value of attribute scrape_error.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def scrape_error
  @scrape_error
end

#screenshot_urlObject (readonly)

Returns the value of attribute screenshot_url.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def screenshot_url
  @screenshot_url
end

Returns the value of attribute sitelinks.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def sitelinks
  @sitelinks
end

#snippetObject (readonly)

Returns the value of attribute snippet.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def snippet
  @snippet
end

#titleObject (readonly)

Returns the value of attribute title.



18
19
20
# File 'lib/serpcheap/models.rb', line 18

def title
  @title
end

Class Method Details

.from_hash(d) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/serpcheap/models.rb', line 34

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