Sha256: 95e68ac6240c101ef6eccca092505bf83e7a3ea9bbd9fddf7f0c72f9b7f5222a

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require "ansi"
require "date"

class DomainCheck::ConsoleFormatter
  def initialize(result)
    @result = result
  end

  def format
    if @result
      domain = @result[:domain].ljust(24).ansi.bold.blue

      if @result[:status] == :available
        status = @result[:status].to_s.upcase.ansi.bold.green
        puts "#{ domain } #{ status }"

      elsif @result[:status] == :registered
        status        = @result[:status].to_s.upcase.ansi.bold.red
        contact_name  = @result[:contact_name]
        contact_email = @result[:contact_email]
        
        created_on    = @result[:created_at]
        created_on    = created_on.to_date.to_s if created_on

        expires_in    = nil
        if @result[:expires_at]
          today = Date.today
          days = (@result[:expires_at].to_date - today).to_i
          expires_in = "#{ days } days"
          if days <= 60
            expires_in = expires_in.ansi.yellow.bold
          end
        end

        params = { contact: contact_name, email: contact_email,
          created: created_on, expires: expires_in }
        params.reject! { |k,v| v.nil? }
        param_string = params.to_a.map { |a| "#{ a[0] }: #{ a[1] }" }.join(", ")
        puts "#{ domain } #{ status }" + 
          (", #{ params.to_a.map { |a| "#{ a[0] }: #{ a[1] }" }.join(", ") }")

      elsif @result[:status] == :unknown
        puts "#{ domain } #{ "UNKNOWN".ansi.red.negative.bold }"

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
domain_check-0.0.1 lib/domain_check/console_formatter.rb