Class: EhbrsRubyUtils::Booking::Parsers::List

Inherits:
Aranha::Parsers::Html::ItemList
  • Object
show all
Defined in:
lib/ehbrs_ruby_utils/booking/parsers/list.rb

Defined Under Namespace

Modules: NodeParserExtra

Constant Summary collapse

ITEMS_XPATH =
'//*[@data-testid="property-card"]'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.testid_xpath(value, *suffixes) ⇒ Object



8
9
10
# File 'lib/ehbrs_ruby_utils/booking/parsers/list.rb', line 8

def testid_xpath(value, *suffixes)
  ([".//*[@data-testid='#{value}']"] + suffixes).join('/')
end

Instance Method Details

#dataObject



27
28
29
# File 'lib/ehbrs_ruby_utils/booking/parsers/list.rb', line 27

def data
  { accommodations: items_data, declared_count: declared_count }
end

#declared_countInteger?

Returns:

  • (Integer, nil)


32
33
34
35
36
# File 'lib/ehbrs_ruby_utils/booking/parsers/list.rb', line 32

def declared_count
  ['', '/span'].lazy
    .map { |e| node_parser.integer_optional_value(nokogiri, "//h1#{e}/text()") }
    .find(&:present?)
end

#items_xpathObject



38
39
40
# File 'lib/ehbrs_ruby_utils/booking/parsers/list.rb', line 38

def items_xpath
  ITEMS_XPATH
end

#node_parserObject



42
43
44
45
46
# File 'lib/ehbrs_ruby_utils/booking/parsers/list.rb', line 42

def node_parser
  r = super
  r.extend(NodeParserExtra)
  r
end