Class: DomainCheck::ConsoleFormatter
- Inherits:
-
Object
- Object
- DomainCheck::ConsoleFormatter
- Defined in:
- lib/domain_check/console_formatter.rb
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(result) ⇒ ConsoleFormatter
constructor
A new instance of ConsoleFormatter.
Constructor Details
#initialize(result) ⇒ ConsoleFormatter
Returns a new instance of ConsoleFormatter.
5 6 7 |
# File 'lib/domain_check/console_formatter.rb', line 5 def initialize(result) @result = result end |
Instance Method Details
#format ⇒ Object
9 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 |
# File 'lib/domain_check/console_formatter.rb', line 9 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 |