class MyPrecious::ColumnOrder
Order of columns in a Markdown table
Contains the default column ordering when constructed. Columns are identified by the Symbol commonly used as an attribute on a dependency info object (e.g. RubyGemInfo
instance). Objects of this class behave to some extent like frozen Array instances.
Constants
- COLUMN_FROM_TEXT_NAME
- DEFAULT
Public Class Methods
Given a text name, derive the equivalent column attribute
# File lib/myprecious.rb, line 408 def self.col_from_text_name(n) n = n.downcase entry = COLUMN_FROM_TEXT_NAME.find {|k, v| k === n} return entry && entry[1] end
# File lib/myprecious.rb, line 357 def initialize super @order = DEFAULT end
Public Instance Methods
Get the n
-th column attribute Symbol
# File lib/myprecious.rb, line 365 def [](n) @order[n] end
# File lib/myprecious.rb, line 373 def each(&blk) @order.each(&blk) end
# File lib/myprecious.rb, line 369 def length @order.length end
Render a line to include in a Markdown table for the given dependency
The dependency must know how to respond to (Ruby) messages (i.e. have attributes) for all columns currently included in the order as represented by this instance.
# File lib/myprecious.rb, line 401 def markdown_columns(dependency) map {|attr| dependency.send(attr)}.join(" | ") end
Update the column order to match those in the given line
Columns not included in the line are appended in the order they appear in the default order.
# File lib/myprecious.rb, line 384 def read_order_from_headers(headers_line) headers = headers_line.split('|').map {|h| h.strip.squeeze(' ')} @order = headers.map {|h| self.class.col_from_text_name(h)}.compact # Add in any missing columns at the end @order.concat(DEFAULT - @order) return @order.dup end