Class: Warp::Dir::Formatter::StoreFormatter
- Defined in:
- lib/warp/dir/formatter.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
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) ⇒ StoreFormatter
constructor
A new instance of StoreFormatter.
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
#store ⇒ Object
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 |