class HTMLPage::Figure

Manages figure enumeration and references.

For example, reference a defined figure:

<p>This is demonstrated in <%= figure.ref :my_fig_name %>.
...
<figure>
  <img>
  <figcaption><%= figure.name :my_fig_name %></figcaption>
</figure>

Public Class Methods

new() click to toggle source
# File lib/html_page.rb, line 170
def initialize
  @figures = Hash.new {|hsh, name| hsh[name] = hsh.size + 1 }
  @names = [] # permits name/ref to be called in any order
end

Public Instance Methods

name(figname) click to toggle source
# File lib/html_page.rb, line 175
def name figname
  if @names.include? figname
    raise "Figure name `#{figname}' already defined."
  else
    @names << figname
  end
  "<span class='figname'>FigureĀ #{@figures[figname]}.</span>"
end
ref(figname) click to toggle source
# File lib/html_page.rb, line 184
def ref figname
  "<span class='figref'>FigureĀ #{@figures[figname]}</span>"
end