<commit_before>module Shiplogs
  module Parser
    class Html
      attr_accessor :url
      
      def initialize(url)
        @url = url
      end
      
      def document
        @document ||= Nokogiri::HTML(open(@url))
      end
      
      def content
        document.css('div#content').first.children
      end
      
      def pages
        if @pages.nil?
          @pages = []
          previous_node = nil
          current_page = nil
          content.css('p').each do |node|
            if node[:class] == 'center' and previous_node[:class] != 'center'
              #found title item
              unless current_page.nil?
                @pages << current_page 
              end
              
              current_page = Page.new(title_content(node))
            elsif !current_page.nil? and !node.nil?
              current_page.add_content page_content(node)
            end
            previous_node = node
          end
        end
        
        @pages
      end
      
      def title_content(node)
        node.content.gsub("\n", " ").strip
      end
      
      def page_content(node)
        node.content.gsub("\n", " ").strip + "\n"
      end
    end
  end
end<commit_msg>fixing issue where pages need to be combined<commit_after>module Shiplogs
  module Parser
    class Html
      attr_accessor :url
      
      def initialize(url)
        @url = url
      end
      
      def document
        @document ||= Nokogiri::HTML(open(@url))
      end
      
      def content
        document.css('div#content').first.children
      end
      
      def pages
        if @pages.nil?
          @pages = []
          previous_node = nil
          current_page = nil
          content.css('p').each do |node|
            next if node.nil?
            if title_node?(node)
              if title_node?(previous_node)
                #found second title for current page
                current_page.title += " - #{title_content(node)}"
              else
                #found new page
                unless current_page.nil?
                  @pages << current_page 
                end
                current_page = Page.new(title_content(node))
              end
            elsif !current_page.nil? and !node.nil?
              current_page.add_content page_content(node)
            end
            previous_node = node
          end
        end
        
        @pages
      end
      
      def title_node?(node)
        return false if node.nil?
        node[:class] == 'center' and title_content(node).length > 0
      end
      
      def title_content(node)
        node.content.gsub("\n", " ").strip
      end
      
      def page_content(node)
        node.content.gsub("\n", " ").strip + "\n"
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08827785817655572, 'fraction_numerical': 0.000361794500723589, 'mean_word_length': 1.3333333333333333, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, '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': '1654369', 'n_tokens_mistral': 774, 'n_tokens_neox': 763, 'n_words': 183}