<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'
require 'whois/answer/parser/scanners/whoisit'


module Whois
  class Answer
    class Parser

      #
      # = whois.nic.it parser
      #
      # Parser for the whois.nic.it server.
      #
      class WhoisNicIt < Base
        include Features::Ast


        property_supported :disclaimer do
          node("Disclaimer")
        end


        property_supported :domain do
          node("Domain") { |raw| raw.downcase }
        end

        property_not_supported :domain_id


        property_not_supported :referral_whois

        property_not_supported :referral_url


        property_supported :status do
          case node("Status").to_s.downcase
          when /^ok/, "active"
            :registered
          when /\bclient/
            :registered
          when "pendingdelete / redemptionperiod", "grace-period"
            :registered
          when "available"
            :available
          else
            Whois.bug!(ParserError, "Unknown status `#{node("Status")}'.")
          end
        end

        property_supported :available? do
          node("Status") == "AVAILABLE"
        end

        property_supported :registered? do
          !available?
        end


        property_supported :created_on do
          node("Created") { |raw| Time.parse(raw) }
        end

        property_supported :updated_on do
          node("Last Update") { |raw| Time.parse(raw) }
        end

        property_supported :expires_on do
          node("Expire Date") { |raw| Time.parse(raw) }
        end


        property_supported :registrar do
          node("Registrar") do |raw|
            Answer::Registrar.new(
              :id           => raw["Name"],
              :name         => raw["Name"],
              :organization => raw["Organization"]
            )
          end
        end


        property_supported :registrant_contact do
          contact("Registrant", Whois::Answer::Contact::TYPE_REGISTRANT)
        end

        property_supported :admin_contact do
          contact("Admin Contact", Whois::Answer::Contact::TYPE_ADMIN)
        end

        property_supported :technical_contact do
          contact("Technical Contacts", Whois::Answer::Contact::TYPE_TECHNICAL)
        end


        property_supported :nameservers do
          (node("Nameservers") || []).map do |name|
            Answer::Nameserver.new(name)
          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
          Scanners::Whoisit.new(content_for_scanner).parse
        end


        protected

          def contact(element, type)
            node(element) do |raw|
              address = (raw["Address"] || "").split("\n")
              Answer::Contact.new(
                :id           => raw["ContactID"],
                :type         => type,
                :name         => raw["Name"],
                :organization => raw["Organization"],
                :address      => address[0],
                :city         => address[1],
                :zip          => address[2],
                :state        => address[3],
                :country_code => address[4],
                :created_on   => raw["Created"] ? Time.parse(raw["Created"]) : nil,
                :updated_on   => raw["Last Update"] ? Time.parse(raw["Created"]) : nil
              )
            end
          end
<commit_msg>whois.nic.it parses Created instead of Last Update<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/whoisit'


module Whois
  class Answer
    class Parser

      #
      # = whois.nic.it parser
      #
      # Parser for the whois.nic.it server.
      #
      class WhoisNicIt < Base
        include Features::Ast


        property_supported :disclaimer do
          node("Disclaimer")
        end


        property_supported :domain do
          node("Domain") { |raw| raw.downcase }
        end

        property_not_supported :domain_id


        property_not_supported :referral_whois

        property_not_supported :referral_url


        property_supported :status do
          case node("Status").to_s.downcase
          when /^ok/, "active"
            :registered
          when /\bclient/
            :registered
          when "pendingdelete / redemptionperiod", "grace-period"
            :registered
          when "available"
            :available
          else
            Whois.bug!(ParserError, "Unknown status `#{node("Status")}'.")
          end
        end

        property_supported :available? do
          node("Status") == "AVAILABLE"
        end

        property_supported :registered? do
          !available?
        end


        property_supported :created_on do
          node("Created") { |raw| Time.parse(raw) }
        end

        property_supported :updated_on do
          node("Last Update") { |raw| Time.parse(raw) }
        end

        property_supported :expires_on do
          node("Expire Date") { |raw| Time.parse(raw) }
        end


        property_supported :registrar do
          node("Registrar") do |raw|
            Answer::Registrar.new(
              :id           => raw["Name"],
              :name         => raw["Name"],
              :organization => raw["Organization"]
            )
          end
        end


        property_supported :registrant_contact do
          contact("Registrant", Whois::Answer::Contact::TYPE_REGISTRANT)
        end

        property_supported :admin_contact do
          contact("Admin Contact", Whois::Answer::Contact::TYPE_ADMIN)
        end

        property_supported :technical_contact do
          contact("Technical Contacts", Whois::Answer::Contact::TYPE_TECHNICAL)
        end


        property_supported :nameservers do
          (node("Nameservers") || []).map do |name|
            Answer::Nameserver.new(name)
          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
          Scanners::Whoisit.new(content_for_scanner).parse
        end


        protected

          def contact(element, type)
            node(element) do |raw|
              address = (raw["Address"] || "").split("\n")
              Answer::Contact.new(
                :id           => raw["ContactID"],
                :type         => type,
                :name         => raw["Name"],
                :organization => raw["Organization"],
                :address      => address[0],
                :city         => address[1],
                :zip          => address[2],
                :state        => address[3],
                :country_code => address[4],
                :created_on   => raw["Created"] ? Time.parse(raw["Created"]) : nil,
                :updated_on   => raw["Last Update"] ? Time.parse(raw["Last Update"]) : nil
              )
            end
          end

{'fraction_non_alphanumeric': 0.11026969576192375, 'fraction_numerical': 0.0013285505513484788, 'mean_word_length': 1.6432584269662922, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, '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': '7472949', 'n_tokens_mistral': 2112, 'n_tokens_neox': 1987, 'n_words': 459}