Class: Warp::Dir::Formatter

Inherits:
Object show all
Defined in:
lib/warp/dir/formatter.rb

Defined Under Namespace

Classes: PointFormatter, StoreFormatter

Constant Summary collapse

DEFAULT_FORMAT =
:ascii

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Formatter

Returns a new instance of Formatter.



12
13
14
15
# File 'lib/warp/dir/formatter.rb', line 12

def initialize(store)
  @store  = store
  @config = store.config
end

Instance Attribute Details

#storeObject

Returns the value of attribute store.



10
11
12
# File 'lib/warp/dir/formatter.rb', line 10

def store
  @store
end

Instance Method Details

#format_point(point, *args) ⇒ Object



26
27
28
# File 'lib/warp/dir/formatter.rb', line 26

def format_point(point, *args)
  PointFormatter.new(point).format(*args)
end

#format_store(*args) ⇒ Object



30
31
32
# File 'lib/warp/dir/formatter.rb', line 30

def format_store(*args)
  StoreFormatter.new(store).format(*args)
end

#happy(message: nil) ⇒ Object



34
35
36
# File 'lib/warp/dir/formatter.rb', line 34

def happy(message: nil)
  STDOUT.printf(message.blue.bold)
end

#unhappy(exception: nil, message: nil) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/warp/dir/formatter.rb', line 17

def unhappy(exception: nil, message: nil)
  out = 'Whoops! – '.white
  out << "#{exception.message} ".red if exception && !message
  out << "#{message} ".red if !exception && message
  out << "#{exception.message}:\n#{message}".red if message && exception
  out << "\n"
  print ? STDERR.printf(out) : out
end