Class: StonesSpec::HtmlBoardRenderer

Inherits:
Object
  • Object
show all
Includes:
WithGobstonesCSS
Defined in:
lib/renderers/html_board_renderer.rb

Instance Method Summary collapse

Methods included from WithGobstonesCSS

#gobstones_css

Constructor Details

#initialize(options = {}) ⇒ HtmlBoardRenderer

Returns a new instance of HtmlBoardRenderer.



7
8
9
# File 'lib/renderers/html_board_renderer.rb', line 7

def initialize(options = {})
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



18
19
20
# File 'lib/renderers/html_board_renderer.rb', line 18

def method_missing(name)
  @options[name]
end

Instance Method Details

#render(board) ⇒ Object



11
12
13
14
15
16
# File 'lib/renderers/html_board_renderer.rb', line 11

def render(board)
"<style type=\"text/css\">
#{render_css}</style>

#{render_html board}"
end

#render_cssObject



32
33
34
# File 'lib/renderers/html_board_renderer.rb', line 32

def render_css
  gobstones_css '9pt', 30
end

#render_html(board) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/renderers/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