Class: DomainCheck::ConsoleFormatter
- Inherits:
-
Object
- Object
- DomainCheck::ConsoleFormatter
- Defined in:
- lib/domain_check/console_formatter.rb
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(result, available_only = false) ⇒ ConsoleFormatter
constructor
A new instance of ConsoleFormatter.
Constructor Details
#initialize(result, available_only = false) ⇒ ConsoleFormatter
Returns a new instance of ConsoleFormatter.
5 6 7 8 |
# File 'lib/domain_check/console_formatter.rb', line 5 def initialize(result, available_only = false) @result = result @available_only = available_only end |
Instance Method Details
#format ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/domain_check/console_formatter.rb', line 10 def format if @result return if @available_only && @result[:status] != :available 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 }" + (", #{ param_string }" if param_string) elsif @result[:status] == :unknown puts "#{ domain } #{ "UNKNOWN".ansi.red.negative.bold }" end end end |