class StonesSpec::HtmlBoardRenderer
Public Class Methods
new(options = {})
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 7 def initialize(options = {}) @options = options end
Public Instance Methods
method_missing(name)
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 18 def method_missing(name) @options[name] end
render(board)
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 11 def render(board) "<style type=\"text/css\"> #{render_css}</style> #{render_html board}" end
render_css()
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 32 def render_css gobstones_css '9pt', 30 end
render_html(board)
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 22 def render_html(board) width, height = board.size "#{table_title} #{html_row_titles width, 'top'} #{(0...height).to_a.reverse.map {|y| html_row(board, y)}.join}#{html_row_titles width, 'bottom'} </table> " end
Private Instance Methods
html_cell(board, position)
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 52 def html_cell(board, position) cell = board.cell_at position " <td class=\"gc#{board.head_position == position ? ' gh' : ''}\"> <table> <tr>#{html_stone cell, :black}#{html_stone cell, :blue}</tr> <tr>#{html_stone cell, :red}#{html_stone cell, :green}</tr> </table> </td>" end
html_row(board, y)
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 43 def html_row(board, y) " <tr> <td class=\"lv\">#{y}</td> #{(0...board.size[0]).map {|x| html_cell board, [x, y] }.join "\n"} <td class=\"lv\">#{y}</td> </tr> " end
html_row_titles(width, caption)
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 73 def html_row_titles(width, caption) "<tr><td class=\"lx #{caption}_left\"></td>#{(0...width).map {|x| "<td class=\"lh\">#{x}</td>"}.join}<td class=\"lx #{caption}_right\"></td></tr>" end
html_stone(cell, color)
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 63 def html_stone(cell, color) quantity = cell[color] if cell[color] == 0 '<td><div class="O"></div></td>' else "<td><div class=\"gbs_stone #{Stones::Color.all_with_names.invert[color][0]}\"><span>#{quantity}</span></div></td>" end end
table_title()
click to toggle source
# File lib/stones_spec/html_board_renderer.rb, line 38 def table_title base = "<table class=\"gbs_board\">" caption ? base + "\n<caption>#{caption}</caption>" : base end