Class: Warp::Dir::Formatter::StoreFormatter
- Defined in:
- lib/warp/dir/formatter.rb
Instance Attribute Summary collapse
-
#points ⇒ Object
Returns the value of attribute points.
Instance Method Summary collapse
-
#format(type = DEFAULT_FORMAT, sort_field = :name) ⇒ Object
find the widest warp point name, and indent them all based on that.
-
#initialize(store_or_points) ⇒ StoreFormatter
constructor
A new instance of StoreFormatter.
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
#points ⇒ Object
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 |