<< 前 ホーム 次 >>

bakaid: 20050803

とりあえずSelect Allしてみる:
              
     
          
     
          

生成コード。まだ汚いけど:

require 'stringio'

LETTERS = {}

class TableString
  def initialize(str)
    @chars = []
    str.each_byte do |b|
      letter = b.chr.upcase
      next unless LETTERS.key?(letter)
      @chars << LETTERS[letter]
    end
  end

  def to_s
    StringIO.open('', 'w') do |output|
      display(output)
      output.string
    end
  end

  def display(output)
    output.puts('<table>')
    # 1
    output.puts('<tr>')
    cols = @chars.collect{|ech| ech.td(0)}
    output.puts(cols.join('<td></td>'))
    output.puts('</tr>')
    # 2
    output.puts('<tr>')
    cols = @chars.collect{|ech| ech.td(1)}
    output.puts(cols.join('<td></td>'))
    output.puts('</tr>')
    # 3
    output.puts('<tr>')
    cols = @chars.collect{|ech| ech.td(2)}
    output.puts(cols.join('<td></td>'))
    output.puts('</tr>')
    # 4
    output.puts('<tr>')
    cols = @chars.collect{|ech| ech.td(3)}
    output.puts(cols.join('<td></td>'))
    output.puts('</tr>')
    # 5
    output.puts('<tr>')
    cols = @chars.collect{|ech| ech.td(4)}
    output.puts(cols.join('<td></td>'))
    output.puts('</tr>')
    output.puts('</table>')
  end
end

class TableChar
  def initialize(letter, tds)
    @letter = letter
    @tds = tds
  end

  def td(n)
    return @tds[n]
  end
end

LETTERS['A'] =
  TableChar.new('A', [
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>'
                ])

LETTERS['B'] =
  TableChar.new('B', [
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['C'] =
  TableChar.new('C', [
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['D'] =
  TableChar.new('D', [
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['E'] =
  TableChar.new('E', [
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>'
                ])

LETTERS['F'] =
  TableChar.new('F', [
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>'
                ])

LETTERS['G'] =
  TableChar.new('G', [
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>',
                  '<td>*</td><td></td><td></td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['H'] =
  TableChar.new('H', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>'
                ])

LETTERS['I'] =
  TableChar.new('I', [
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['J'] =
  TableChar.new('J', [
                  '<td></td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['K'] =
  TableChar.new('K', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td>*</td><td></td>',
                  '<td>*</td><td>*</td><td>*</td><td></td><td></td>',
                  '<td>*</td><td></td><td></td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>'
                ])

LETTERS['L'] =
  TableChar.new('L', [
                 '<td>*</td><td></td><td></td><td></td><td></td>',
                 '<td>*</td><td></td><td></td><td></td><td></td>',
                 '<td>*</td><td></td><td></td><td></td><td></td>',
                 '<td>*</td><td></td><td></td><td></td><td></td>',
                 '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>'
               ])

LETTERS['M'] =
  TableChar.new('M', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td></td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td>*</td><td></td><td>*</td>',
                  '<td>*</td><td></td><td>*</td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>'
                ])

LETTERS['N'] =
  TableChar.new('N', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td>*</td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>'
                ])

LETTERS['O'] =
  TableChar.new('O', [
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['P'] =
  TableChar.new('P', [
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>'
                ])

LETTERS['Q'] =
  TableChar.new('Q', [
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td>*</td><td></td><td>*</td>',
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td></td><td></td><td></td><td></td><td>*</td>'
                ])

LETTERS['R'] =
  TableChar.new('R', [
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td>*</td><td></td><td>*</td><td></td><td></td>',
                  '<td>*</td><td></td><td></td><td>*</td><td></td>'
                ])

LETTERS['S'] =
  TableChar.new('S', [
                  '<td></td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td></td>',
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>',
                  '<td></td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['T'] =
  TableChar.new('T', [
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>'
                ])

LETTERS['U'] =
  TableChar.new('U', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td>*</td><td>*</td><td>*</td><td></td>'
                ])

LETTERS['V'] =
  TableChar.new('V', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td>*</td><td></td><td>*</td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>'
                ])

LETTERS['W'] =
  TableChar.new('W', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td>*</td><td></td><td>*</td><td></td><td>*</td>',
                  '<td>*</td><td></td><td>*</td><td></td><td>*</td>',
                  '<td>*</td><td>*</td><td></td><td>*</td><td>*</td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>'
                ])

LETTERS['X'] =
  TableChar.new('X', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td>*</td><td></td><td>*</td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td>*</td><td></td><td>*</td><td></td>',
                  '<td>*</td><td></td><td></td><td></td><td>*</td>'
                ])

LETTERS['Y'] =
  TableChar.new('Y', [
                  '<td>*</td><td></td><td></td><td></td><td>*</td>',
                  '<td></td><td>*</td><td></td><td>*</td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>'
                ])

LETTERS['Z'] =
  TableChar.new('Z', [
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>',
                  '<td></td><td></td><td></td><td>*</td><td></td>',
                  '<td></td><td></td><td>*</td><td></td><td></td>',
                  '<td></td><td>*</td><td></td><td></td><td></td>',
                  '<td>*</td><td>*</td><td>*</td><td>*</td><td>*</td>'

本家Permlink

<< 前 ホーム 次 >>


Copyright © 1905 tko at jitu.org

バカが征く on Rails