Module: EhbrsRubyUtils::Booking::Parsers::List::NodeParserExtra

Defined in:
lib/ehbrs_ruby_utils/booking/parsers/list.rb

Constant Summary collapse

DISTANCE_PARSER =
/\A(\d+)(?:,(\d+))? (m|km)/.to_parser do |m|
  r = m[1].to_f + m[2].if_present(0) { |v| v.to_f / 10.pow(v.length) }
  r /= 1000 if m[3] == 'm'
  r
end

Instance Method Summary collapse

Instance Method Details

#distance_value(node, xpath) ⇒ Float

Parameters:

  • node (Nokogiri::XML::Node)
  • xpath (String)

Returns:

  • (Float)


58
59
60
# File 'lib/ehbrs_ruby_utils/booking/parsers/list.rb', line 58

def distance_value(node, xpath)
  string_value(node, xpath).if_present(nil) { |e| DISTANCE_PARSER.parse!(e) }
end