Class: GetterCyndi5

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

Overview

The main GetterCyndi5 driver

Defined Under Namespace

Classes: Parser, Product, Retriever

Class Method Summary collapse

Class Method Details

.go(options = {}) ⇒ Object

Getter

Example:

>> GetterCyndi5.go(
      base_url = 'https://thehappyco.com',
      products_page_path = '/kelly/products',
      item_row_selector = '.item-row',
      item_anchor_selector = 'div > div.product-desc.text-center > div.product-title > h3 > a',
      item_price_selector = 'div > div.product-desc.text-center > div.product-price',
      price_a_text: 'One Time Purchase',
      price_b_text: 'SmartShip',
      mode = 2,
      filename = './tmp/test_document.html'
  )

Arguments:

base_url: (String)
products_page_path: (String) 
item_row_selector: (String) 
item_anchor_selector: (String)
item_price_selector: (String)
price_a_text: (String)
price_b_text: (String)
mode: (Integer)
  0 = retrieve and parse without saving HTML document to file,
  1 = retrieve and parse saving HTML document to file,
  2 = load and parse HTML document from file
filename: (String)


31
32
33
34
35
36
# File 'lib/getter_cyndi5.rb', line 31

def self.go(options = {})
  all_products = products(**options)
  all_products.each do |product|
    puts "#{product.inspect}"
  end
end

.products(options = {}) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/getter_cyndi5.rb', line 38

def self.products(options = {})
  retriever = Retriever.new(**options)
  retriever.retrieve

  parser = Parser.new(document: retriever.document, **options)
  products = parser.parse
end