Class: Ppp::Card::Html
Constant Summary collapse
- @@SIZES =
{:creditcard => %w[ 85.60mm 53.98mm ]}
Instance Attribute Summary
Attributes inherited from Base
#card_number, #row_count, #title
Instance Method Summary collapse
- #css ⇒ Object
- #html ⇒ Object
-
#initialize(generator, opts = {}) ⇒ Html
constructor
A new instance of Html.
- #to_s ⇒ Object
Methods inherited from Base
#code_length, #codes, #passcode, #passcodes_per_card, #passcodes_per_line, #verify
Constructor Details
#initialize(generator, opts = {}) ⇒ Html
Returns a new instance of Html.
7 8 9 10 11 12 13 |
# File 'lib/ppp/card/html.rb', line 7 def initialize generator, opts={} super = { :font_size => 14, :size => :creditcard }.merge opts @font_size = [ :font_size ] @size = process_size [ :size ] end |
Instance Method Details
#css ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ppp/card/html.rb', line 15 def css %[ <style> .card, .card .title, .card .card_number, .card .codes, .card .codes td { font-family: monospace; font-size: 3.5mm; } .card { background-color: \#fff; margin: 0 auto 0 auto; width: #{width}; height: #{height}; border: 1px solid \#000; border-top: none; border-spacing: 0; } .title { border: 1px solid \#000; border-bottom: 1px solid \#000; background-color: \#eee; text-align: left; padding-left: 1ex; font-weight: bold; } .title td:first-child { width: 2.5em; } .card_number { float: right; margin-right: 1ex; } .card_number:before { content: '['; } .card_number:after { content: ']'; } .codes_heading th { text-align: center; width: #{code_length}em; border-bottom: 1px solid \#aaa; background-color: \#eee; } .codes_heading th:first-child { background-color: \#fff; border-right: 1px solid \#aaa; } .codes_heading th:last-child { border-right: none; } .codes td { padding: 0; margin: 0; text-align: center; border-right: 1px solid \#aaa; border-bottom: 1px solid \#aaa; } .codes tr td:first-child { text-align: right; padding-right: 0.5em; font-weight: bold; background-color: \#eee; border-right: 1px solid \#aaa; } .codes tr td:first-child { border-bottom: none; } .codes tr td:last-child { border-right: none; } .codes tr:last-child td { border-bottom: none; } </style> ] end |
#html ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ppp/card/html.rb', line 81 def html rows = codes.each_with_index.collect do |row, i| cols = row.collect { |code| " <td>#{code}</td>" }.join(?\n) "<tr>\n <td>#{i+1}:</td>\n#{cols}</tr>" end.join(?\n) %[ <table class="card"> <caption class="title"> #{@title} <span class="card_number">#{card_number}</span> </caption> <colgroup span="1"> <colgroup span="#{passcodes_per_line}"> <thead class="codes_heading"> <th> </th> #{ passcodes_per_line.times.collect { |i| %[<th>#{column_label(i+1)}</th>] }.join ?\n } </thead> <tbody class="codes"> #{rows} </tbody> </table> ] end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/ppp/card/html.rb', line 106 def to_s "#{css}\n\n#{html}" end |