Module: Assert::View::Helpers::LeftrightColumns

Defined in:
lib/assert/view/helpers/leftright_columns.rb

Instance Method Summary collapse

Instance Method Details

#left_column(text, opts = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/assert/view/helpers/leftright_columns.rb', line 5

def left_column(text, opts={})
  col_width = opts[:width] || self.view.left_column_width
  __ case view.options.left_column_justify
  when :left
    text.to_s+" "*(col_width-(text.to_s.size))
  else
    " "*(col_width-(text.to_s.size))+text.to_s+" "
  end, false
end

#right_column(text, opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/assert/view/helpers/leftright_columns.rb', line 15

def right_column(text, opts={})
  lines = text.split("\n")
  right_columnize(lines.first || "", opts)
  (lines[1..-1] || []).each do |line|
    self.left_column("")
    right_columnize(line, opts)
  end
  __ if opts[:endline]
end

#right_columnize(text, opts = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/assert/view/helpers/leftright_columns.rb', line 25

def right_columnize(text, opts={})
  col_width = opts[:width] || self.view.right_column_width
  # split text into array of limit sizes

  n,r = text.size.divmod(col_width)
  grps = (0..(n-1)).collect do |i|
    i == 0 ? text[i*col_width,col_width] : " "+text[i*col_width,col_width]
  end
  if r > 0
    grps << (n > 0 ? " "+text[-r,r] : text[-r,r])
  end

  __ grps.first
  if grps.size > 1
    grps[1..-1].each do |g|
      self.left_column("")
      __ g
    end
  end
end