Module: Respectable::Util

Defined in:
lib/respectable.rb

Class Method Summary collapse

Class Method Details

.desc_template(block_params) ⇒ Object



41
42
43
44
# File 'lib/respectable.rb', line 41

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) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/respectable.rb', line 55

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) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/respectable.rb', line 46

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