Class: Ppp::Card::Xml

Inherits:
Base
  • Object
show all
Defined in:
lib/ppp/card/xml.rb

Instance Attribute Summary

Attributes inherited from Base

#card_number, #row_count, #title

Instance Method Summary collapse

Methods inherited from Base

#code_length, #codes, #passcode, #passcodes_per_card, #passcodes_per_line, #verify

Constructor Details

#initialize(generator, opts = {}) ⇒ Xml

Returns a new instance of Xml.



5
6
7
# File 'lib/ppp/card/xml.rb', line 5

def initialize generator, opts={}
  super
end

Instance Method Details

#to_sObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ppp/card/xml.rb', line 9

def to_s
  rows = codes.each_with_index.collect do |row, i|
    cols = row.each_with_index.collect { |code, j| "    <column label=\"#{column_label(j+1)}\">#{code}</column>" }.join(?\n)
    "  <row number=\"#{i+1}\">\n#{cols}\n  </row>\n"
  end.join(?\n)

  %[<?xml version="1.0" encoding="UTF-8" ?>\n] +
  %[<card title="#{@title}" number="#{card_number}">\n] +
  rows + 
  %[</card>\n]
end