module Respectable::Util

Public Class Methods

desc_template(block_params) click to toggle source
# File lib/respectable.rb, line 43
def self.desc_template(block_params)
  *desc_args, desc_result = *block_params.map(&:last)
  "yields %{#{desc_result}} for " + desc_args.map {|arg| "#{arg}: %{#{arg}}" }.join(', ')
end
eval_row_items(row, binding) click to toggle source
# File lib/respectable.rb, line 57
def self.eval_row_items(row, binding)
  row.map do |i|
    i = i.sub(/\\(?=|)/, '') # remove escapes for '|'
    # handle `...`
    r = i[/\A`([^`]+)`\z/, 1]
    r ? binding.eval(r) : i
  end
end
table_data(table) click to toggle source
# File lib/respectable.rb, line 48
def self.table_data(table)
  table.split(/\n */).reject {|line| line[/^ *#/] }.map do |line|
    cols = line.split(/ *(?<!\\)\| */)[1..-1]
    comment_col = cols.size
    cols.each_with_index {|col, ix| comment_col = ix if col[/^ *#/] }
    cols[0, comment_col]
  end
end