Class: ISO7816::Card::LoggingCard

Inherits:
Card
  • Object
show all
Defined in:
lib/7816/card.rb

Constant Summary collapse

DEFAULT_DUMP =
lambda {|dir, b|
  prefix = case dir
           when :atr     then "ATR"
           when :send    then "  >"
           when :recv    then "  <"
           when :disco   then "\nCLIENT DISCONNECT"
           else               :comment
           end
  if prefix == :comment
    txt = "\n"
    b.each_line{|line| txt << "      #{line}"}
    txt << "\n\n"     
  else
    "%s %s" % [prefix, ISO7816.b2s(b)]
  end
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Card

#reconnect

Constructor Details

#initialize(card) ⇒ LoggingCard

Returns a new instance of LoggingCard.



99
100
101
102
# File 'lib/7816/card.rb', line 99

def initialize card
  @card = card
  @log = []
end

Instance Attribute Details

#cardObject

Returns the value of attribute card.



98
99
100
# File 'lib/7816/card.rb', line 98

def card
  @card
end

Instance Method Details

#atrObject



103
104
105
# File 'lib/7816/card.rb', line 103

def atr
  @card.atr
end

#comment(txt) ⇒ Object



138
139
140
# File 'lib/7816/card.rb', line 138

def comment txt
  @log.push [:comment, txt]
end

#connect(&block) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/7816/card.rb', line 106

def connect &block
  if block_given?
    @card.connect 
    @log.push [:atr, @card.atr]
    yield self
    disconnect
  else
    @card.connect
    @log.push [:atr, @card.atr]
  end
end

#disconnectObject



118
119
120
121
# File 'lib/7816/card.rb', line 118

def disconnect
  @card.disconnect
  @log.push [:disco, ""]
end

#dump(io = STDOUT, formater = DEFAULT_DUMP) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/7816/card.rb', line 158

def dump io=STDOUT, formater=DEFAULT_DUMP
  @log.each{ |line|
    format = DEFAULT_DUMP.call(line[0], line[1])
    io.puts(format)
  }        
  
end

#receive(le = 1024) ⇒ Object



128
129
130
131
132
# File 'lib/7816/card.rb', line 128

def receive le=1024
  recv = @card.receive(le)
  @log.push [:recv, recv]
  recv
end

#send(bytes) ⇒ Object



123
124
125
126
# File 'lib/7816/card.rb', line 123

def send bytes
  @card.send bytes
  @log.push [:send, bytes]
end

#t0?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/7816/card.rb', line 134

def t0?
  @card.t0?
end