class Nazar::CellFormatter

Attributes

type[R]
value[R]

Public Class Methods

new(value, type: :string) click to toggle source
# File lib/nazar/cell_formatter.rb, line 5
def initialize(value, type: :string)
  @value = value
  @type = type
end

Public Instance Methods

format() click to toggle source
# File lib/nazar/cell_formatter.rb, line 10
def format
  case type
  when :boolean
    format_boolean
  when :integer
    format_number
  else
    value.nil? ? format_nil : inteligent_format
  end
end

Private Instance Methods

format_boolean() click to toggle source
# File lib/nazar/cell_formatter.rb, line 25
def format_boolean
  return format_nil if value.nil?

  true_value, false_value = Nazar.config.formatter.boolean
  Formatter::TRUTHY_VALUES.include?(value.to_s.downcase) ? true_value : false_value
end
format_nil() click to toggle source
# File lib/nazar/cell_formatter.rb, line 32
def format_nil
  pastel.dim(Nazar.config.formatter.nil)
end
format_number() click to toggle source
# File lib/nazar/cell_formatter.rb, line 36
def format_number
  pastel.bright_blue(value)
end
inteligent_format() click to toggle source
# File lib/nazar/cell_formatter.rb, line 40
def inteligent_format
  case value
  when Symbol
    pastel.magenta(":#{value}")
  when Numeric
    format_number
  else
    value.to_s
  end
end
pastel() click to toggle source
# File lib/nazar/cell_formatter.rb, line 51
def pastel
  @pastel ||= Pastel.new(enabled: Nazar.config.colors.enabled)
end