Class: AMarmita::Scrapper

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

Direct Known Subclasses

Cart::Scrapper, Meals::Scrapper, Orders::Scrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(css_parser) ⇒ Scrapper

Returns a new instance of Scrapper.



7
8
9
10
11
# File 'lib/a_marmita/scrapper.rb', line 7

def initialize(css_parser)
  @attributes = { id: 0 }

  @css_parser = css_parser
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/a_marmita/scrapper.rb', line 5

def attributes
  @attributes
end

#css_parserObject (readonly)

Returns the value of attribute css_parser.



5
6
7
# File 'lib/a_marmita/scrapper.rb', line 5

def css_parser
  @css_parser
end

Instance Method Details

#run(options = {}) ⇒ Object



27
28
29
# File 'lib/a_marmita/scrapper.rb', line 27

def run(options = {})
  raise '#run must be implemented'
end

#scrap(options = {}) ⇒ Object



21
22
23
24
25
# File 'lib/a_marmita/scrapper.rb', line 21

def scrap(options = {})
  run(options)
  
  valid? ? @attributes : nil
end

#to_hashObject



17
18
19
# File 'lib/a_marmita/scrapper.rb', line 17

def to_hash
  @attributes
end

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/a_marmita/scrapper.rb', line 13

def valid?
  @attributes[:id] > 0
end