class HighLine::List
List class with some convenience methods like {#col_down}.
def build
def build slice_by_cols transpose if transpose_mode col_down if col_down_mode self end
def col_down
-
(self)
-
def col_down slice_by_rows transpose self end
def cols=(cols)
-
(self)
-
def cols=(cols) @cols = cols build end
def initialize(items, options = {})
def initialize(items, options = {}) @items = items.to_a.dup.freeze @transpose_mode = options.fetch(:transpose) { false } @col_down_mode = options.fetch(:col_down) { false } @cols = options.fetch(:cols) { 1 } build end
def items_sliced_by_cols
def items_sliced_by_cols items.each_slice(cols).to_a end
def items_sliced_by_rows
def items_sliced_by_rows items.each_slice(row_count).to_a end
def list
-
(Array)
- @list.dup
def list @list.dup end
def row_count
def row_count (items.count / cols.to_f).ceil end
def row_join_str_size
-
(Integer)
-
def row_join_str_size row_join_string.size end
def row_join_string
-
(String)
- defaults to " " (space)
def row_join_string @row_join_string ||= " " end
def slice_by_cols
-
(self)
-
def slice_by_cols @list = items_sliced_by_cols self end
def slice_by_rows
-
(self)
-
def slice_by_rows @list = items_sliced_by_rows self end
def stringfy(row)
def stringfy(row) row.compact.join(row_join_string) + "\n" end
def to_a
def to_a list end
def to_s
-
(String)
-
def to_s list.map { |row| stringfy(row) }.join end
def transpose
-
(self)
-
def transpose first_row = @list[0] other_rows = @list[1..-1] @list = first_row.zip(*other_rows) self end