Class: Warp::Dir::Formatter::StoreFormatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ StoreFormatter

Returns a new instance of StoreFormatter.



60
61
62
# File 'lib/warp/dir/formatter.rb', line 60

def initialize(store)
  @store = store
end

Instance Attribute Details

#storeObject

Returns the value of attribute store.



58
59
60
# File 'lib/warp/dir/formatter.rb', line 58

def store
  @store
end

Instance Method Details

#format(type = DEFAULT_FORMAT, sort_field = :name) ⇒ Object

find the widest warp point name, and indent them all based on that. make it easy to extend to other types, and allow the caller to sort by one of the fields.



67
68
69
70
71
72
# File 'lib/warp/dir/formatter.rb', line 67

def format(type = DEFAULT_FORMAT, sort_field = :name)
  longest_key_length = store.points.map(&:name).map(&:length).sort.last
  Warp::Dir.sort_by(store.points, sort_field).map do |point|
    PointFormatter.new(point).format(type, longest_key_length)
  end.join("\n")
end