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_or_points) ⇒ StoreFormatter

Returns a new instance of StoreFormatter.



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

def initialize(store_or_points)
  self.points = store_or_points.is_a?(::Array) ? store_or_points : store_or_points.points
end

Instance Attribute Details

#pointsObject

Returns the value of attribute points.



56
57
58
# File 'lib/warp/dir/formatter.rb', line 56

def points
  @points
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.



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

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