#!/usr/bin/env ruby

require 'cgi'
require 'digit-1'

c = CGI::new( 'html4' )

if c.key?( 'boct' ) # 8=>
  digit = Digit::new( c['toct'][0] )
elsif c.key?( 'bhex' ) # 16=>
  digit = Digit::new( c['thex'][0] )
else # 10=>
  digit = Digit::new( c['tdec'][0] )
end

c.out(){
  <<-EOS
    <html>
    <head>
      <title>Digit - WebUnit Sample -</title>
    </head>
    <body>
      <div align=center>
        <hr>
          <form method='post'>
          <table border=0>
            <tr>
              <td>#{ c.text_field( 'toct', digit.to_s( 8 ), 8 ) }</td>
              <td>#{ c.text_field( 'tdec', digit.to_s( 10 ), 8 ) }</td>
              <td>#{ c.text_field( 'thex', digit.to_s( 16 ), 8 ) }</td>
            </tr>
            <tr>
              <td align='center'>#{ c.submit( '8=>', 'boct' ) }</td>
              <td align='center'>#{ c.submit( '10=>', 'bdec' ) }</td>
              <td align='center'>#{ c.submit( '16=>', 'bhex' ) }</td>
            </tr>
          </table>
         </form>
        <hr>
      </div>
    </body>
    </html>
  EOS
}
