<commit_before>#
# = Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
#
# Category::    Net
# Package::     Whois
# Author::      <NAME> <<EMAIL>>
# License::     MIT License
#
#--
#
#++


require 'whois/answer/parser/base'


module Whois
  class Answer
    class Parser

      #
      # = whois.tld.ee parser
      #
      # Parser for the whois.tld.ee server.
      #
      # NOTE: This parser is just a stub and provides only a few basic methods
      # to check for domain availability and get domain status.
      # Please consider to contribute implementing missing methods.
      # See WhoisNicIt parser for an explanation of all available methods
      # and examples.
      #
      class WhoisTldEe < Base
        include Features::Ast

        property_supported :status do
          if content_for_scanner =~ /status:\s+(.+)\n/
            case $1.downcase
              when "paid and in zone" then :registered
              # NEWSTATUS
              when "expired" then :expired
              else
                Whois.bug!(ParserError, "Unknown status `#{$1}'.")
            end
          else
            :available
          end
        end

        property_supported :available? do
          !!(content_for_scanner =~ /^%ERROR:101: no entries found/)
        end

        property_supported :registered? do
          !available?
        end


        property_supported :created_on do
          if content_for_scanner =~ /registered:\s+(.+?)\n/
            Time.parse($1)
          end
        end

        property_supported :updated_on do
          if content_for_scanner =~ /changed:\s+(.+?)\n/
            Time.parse($1)
          end
        end

        property_supported :expires_on do
          if content_for_scanner =~ /expire:\s+(.+?)\n/
            Time.parse($1)
          end
        end


        property_supported :registrar do
          if content_for_scanner =~ /registrar:\s+(.*)\n/
            Whois::Answer::Registrar.new(
                :id => $1,
                :name => $1
            )
          end
        end

        property_supported :admin_contact do
          if content_for_scanner =~ /admin-c:\s+(.*)\n/
            contact($1, Whois::Answer::Contact::TYPE_ADMIN)
          end
        end

        property_supported :registrant_contact do
          if content_for_scanner =~ /registrant:\s+(.*)\n/
            contact($1, Whois::Answer::Contact::TYPE_REGISTRANT)
          end
        end

        property_not_supported :technical_contact


        property_supported :nameservers do
          content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |line|
            if line =~ /(.+) \((.+)\)/
              Answer::Nameserver.new($1, $2)
            else
              Answer::Nameserver.new(line)
            end
          end
        end


        protected

          def parse
            Scanner.new(content_for_scanner).parse
          end

          def contact(element, type)
            node(element) do |raw|
              Answer::Contact.new(
                :id             => element,
                :type           => type,
                :name           => raw['name'],
                :organization   => raw['org'],
                :created_on     => Time.parse(raw['created'])
              )
            end
          end

          class Scanner

            def initialize(content)
              @input = StringScanner.new(content)
            end

            def parse
              @ast = Hash.new
              while !@input.eos?
                if @input.scan(/contact:\s+(.*)\n/)
                  section = @input[1].strip
                  content = Hash.new

                  while @input.scan(/(.*?):\s+(.*?)\n/)
                    content[@input[1]] = @input[2]
                  end

                  @ast[section] = content
                else
                  @input.scan(/(.*)\n/)
                end
              end
              @ast
            end
          end

      end
    end
  end
end<commit_msg>WhoisTldEe::Scanner not extends Scanners::Base<commit_after>#
# = Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
#
# Category::    Net
# Package::     Whois
# Author::      <NAME> <<EMAIL>>
# License::     MIT License
#
#--
#
#++


require 'whois/answer/parser/base'
require 'whois/answer/parser/scanners/base'


module Whois
  class Answer
    class Parser

      #
      # = whois.tld.ee parser
      #
      # Parser for the whois.tld.ee server.
      #
      # NOTE: This parser is just a stub and provides only a few basic methods
      # to check for domain availability and get domain status.
      # Please consider to contribute implementing missing methods.
      # See WhoisNicIt parser for an explanation of all available methods
      # and examples.
      #
      class WhoisTldEe < Base
        include Features::Ast

        property_supported :status do
          if content_for_scanner =~ /status:\s+(.+)\n/
            case $1.downcase
              when "paid and in zone" then :registered
              # NEWSTATUS
              when "expired" then :expired
              else
                Whois.bug!(ParserError, "Unknown status `#{$1}'.")
            end
          else
            :available
          end
        end

        property_supported :available? do
          !!(content_for_scanner =~ /^%ERROR:101: no entries found/)
        end

        property_supported :registered? do
          !available?
        end


        property_supported :created_on do
          if content_for_scanner =~ /registered:\s+(.+?)\n/
            Time.parse($1)
          end
        end

        property_supported :updated_on do
          if content_for_scanner =~ /changed:\s+(.+?)\n/
            Time.parse($1)
          end
        end

        property_supported :expires_on do
          if content_for_scanner =~ /expire:\s+(.+?)\n/
            Time.parse($1)
          end
        end


        property_supported :registrar do
          if content_for_scanner =~ /registrar:\s+(.*)\n/
            Whois::Answer::Registrar.new(
                :id => $1,
                :name => $1
            )
          end
        end

        property_supported :admin_contact do
          if content_for_scanner =~ /admin-c:\s+(.*)\n/
            contact($1, Whois::Answer::Contact::TYPE_ADMIN)
          end
        end

        property_supported :registrant_contact do
          if content_for_scanner =~ /registrant:\s+(.*)\n/
            contact($1, Whois::Answer::Contact::TYPE_REGISTRANT)
          end
        end

        property_not_supported :technical_contact


        property_supported :nameservers do
          content_for_scanner.scan(/nserver:\s+(.+)\n/).flatten.map do |line|
            if line =~ /(.+) \((.+)\)/
              Answer::Nameserver.new($1, $2)
            else
              Answer::Nameserver.new(line)
            end
          end
        end


        # Initializes a new {Scanner} instance
        # passing the {Whois::Answer::Parser::Base#content_for_scanner}
        # and calls +parse+ on it.
        #
        # @return [Hash]
        def parse
          Scanner.new(content_for_scanner).parse
        end


        protected

          def contact(element, type)
            node(element) do |raw|
              Answer::Contact.new(
                :id             => element,
                :type           => type,
                :name           => raw['name'],
                :organization   => raw['org'],
                :created_on     => Time.parse(raw['created'])
              )
            end
          end


          class Scanner < Scanners::Base

            def parse_content
              if @input.scan(/contact:\s+(.*)\n/)
                section = @input[1].strip
                content = {}

                while @input.scan(/(.*?):\s+(.*?)\n/)
                  content[@input[1]] = @input[2]
                end

                @ast[section] = content
              # FIXME: incomplete scanner, it skips all the properties
              else
                @input.scan(/(.*)\n/)
              end
            end

          end

      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1075085324232082, 'fraction_numerical': 0.004144319843978547, 'mean_word_length': 1.3665993654456303, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 23, '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': '7136091', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2223, 'n_words': 546}