<commit_before>require "hotel_beds/hotel_search/parser/price"
require "hotel_beds/model/available_room"

module HotelBeds
  module HotelSearch
    module Parser
      class Room
        def self.call(*args, &block)
          new(*args, &block).call
        end

        attr_accessor :room, :check_in_date, :check_out_date
        private :room=, :check_in_date=, :check_out_date=

        def initialize(room, check_in_date:, check_out_date:)
          self.room = room
          self.check_in_date = check_in_date
          self.check_out_date = check_out_date
          freeze
        end

        def call
          HotelBeds::Model::AvailableRoom.new({
            id: room.at_css("HotelRoom").attr("SHRUI"),
            room_count: room.at_css("HotelOccupancy RoomCount").content,
            adult_count: room.at_css("HotelOccupancy AdultCount").content,
            child_count: room.at_css("HotelOccupancy ChildCount").content,
            number_available: room.at_css("HotelRoom").attr("availCount"),
            description: room.at_css("HotelRoom RoomType").content,
            board: room.at_css("HotelRoom Board").content,
            board_code: room.at_css("HotelRoom Board").attr("code"),
            room_type_code: room.at_css("HotelRoom RoomType").attr("code"),
            room_type_characteristic: room.at_css("HotelRoom RoomType").attr("characteristic"),
            price: total_price,
            rates: parse_price_list(room.css("Price PriceList Price"))
          })
        end

        private
        def total_price
          raw = ((room.at_css("HotelRoom") > "Price") > "Amount").first.content
          BigDecimal.new(raw.to_s)
        end

        def parse_price_list(prices)
          if prices.empty?
            dates = (check_in_date..check_out_date).to_a
            amount = (total_price / dates)
            dates.inject(Hash.new) do |result, date|
              result.merge(date => amount)<commit_msg>Bug fix: missing .size on array broke division of room price<commit_after>require "hotel_beds/hotel_search/parser/price"
require "hotel_beds/model/available_room"

module HotelBeds
  module HotelSearch
    module Parser
      class Room
        def self.call(*args, &block)
          new(*args, &block).call
        end

        attr_accessor :room, :check_in_date, :check_out_date
        private :room=, :check_in_date=, :check_out_date=

        def initialize(room, check_in_date:, check_out_date:)
          self.room = room
          self.check_in_date = check_in_date
          self.check_out_date = check_out_date
          freeze
        end

        def call
          HotelBeds::Model::AvailableRoom.new({
            id: room.at_css("HotelRoom").attr("SHRUI"),
            room_count: room.at_css("HotelOccupancy RoomCount").content,
            adult_count: room.at_css("HotelOccupancy AdultCount").content,
            child_count: room.at_css("HotelOccupancy ChildCount").content,
            number_available: room.at_css("HotelRoom").attr("availCount"),
            description: room.at_css("HotelRoom RoomType").content,
            board: room.at_css("HotelRoom Board").content,
            board_code: room.at_css("HotelRoom Board").attr("code"),
            room_type_code: room.at_css("HotelRoom RoomType").attr("code"),
            room_type_characteristic: room.at_css("HotelRoom RoomType").attr("characteristic"),
            price: total_price,
            rates: parse_price_list(room.css("Price PriceList Price"))
          })
        end

        private
        def total_price
          raw = ((room.at_css("HotelRoom") > "Price") > "Amount").first.content
          BigDecimal.new(raw.to_s)
        end

        def parse_price_list(prices)
          if prices.empty?
            dates = (check_in_date..check_out_date).to_a
            amount = total_price / dates.size
            dates.inject(Hash.new) do |result, date|
              result.merge(date => amount)
{'fraction_non_alphanumeric': 0.10973137354282818, 'fraction_numerical': 0.0, 'mean_word_length': 2.4653204565408253, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5096489', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1181, 'n_words': 209}