ppp 0.1.5.alpha → 0.1.6.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ppp/card/base.rb +37 -13
- data/lib/ppp/card/plain.rb +1 -1
- data/lib/ppp/version.rb +1 -1
- metadata +1 -1
data/lib/ppp/card/base.rb
CHANGED
@@ -7,10 +7,11 @@ module Ppp
|
|
7
7
|
|
8
8
|
@@CHARS_PER_LINE = 34
|
9
9
|
@@FIRST_COLUMN = ?A
|
10
|
-
@@ROW_COL_PATTERN = /[[:digit:]][[:alpha:]]/
|
10
|
+
@@ROW_COL_PATTERN = /([[:digit:]]+)([[:alpha:]])/
|
11
11
|
|
12
|
-
@@ERROR_BAD_ROW_COL
|
13
|
-
@@ERROR_LONG_CODES
|
12
|
+
@@ERROR_BAD_ROW_COL = %[Expected a string with exactly one integer followed by one letter, got "%s"]
|
13
|
+
@@ERROR_LONG_CODES = %[Passcodes longer than 16 characters are too long for printing]
|
14
|
+
@@ERROR_WRONG_NUM_ARGS = %[Wrong number of arguments. Expected %s, got %d]
|
14
15
|
|
15
16
|
def initialize generator, opts={}
|
16
17
|
@generator = generator
|
@@ -44,28 +45,51 @@ module Ppp
|
|
44
45
|
|
45
46
|
def codes
|
46
47
|
(1..row_count).collect do |row|
|
47
|
-
card_offset = (card_number-1) * passcodes_per_card
|
48
48
|
offset = card_offset + ((row-1) * passcodes_per_line)
|
49
|
-
|
50
|
-
@generator.passcodes
|
49
|
+
|
50
|
+
@generator.passcodes offset, passcodes_per_line
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def passcode
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def passcode *args
|
55
|
+
case args.size
|
56
|
+
when 1
|
57
|
+
match = @@ROW_COL_PATTERN.match( args.first )
|
58
|
+
raise ArgumentError.new( @@ERROR_BAD_ROW_COL % args.first ) unless match
|
59
|
+
row = match[1]
|
60
|
+
col = match[2]
|
61
|
+
when 2
|
62
|
+
(row, col) = args
|
63
|
+
else
|
64
|
+
raise ArgumentError.new( @@ERROR_WRONG_NUM_ARGS % ['1 or 2', args.size] )
|
65
|
+
end
|
58
66
|
|
59
|
-
def passcode row, col
|
60
67
|
col_offset = col.ord - @@FIRST_COLUMN.ord
|
61
|
-
row_offset = row - 1
|
68
|
+
row_offset = row.to_i - 1
|
69
|
+
|
70
|
+
offset = row_offset * passcodes_per_line + col_offset
|
71
|
+
offset = card_offset + offset
|
72
|
+
@generator.passcode offset
|
73
|
+
end
|
74
|
+
|
75
|
+
def verify *args
|
76
|
+
given_code = args.pop
|
77
|
+
given_code == passcode( *args )
|
78
|
+
end
|
62
79
|
|
63
|
-
|
80
|
+
def row_label row_number
|
81
|
+
"#{row_number + 1}:"
|
64
82
|
end
|
65
83
|
|
66
84
|
def column_label column_number
|
67
85
|
(@@FIRST_COLUMN.ord + (column_number - 1)).chr
|
68
86
|
end
|
87
|
+
|
88
|
+
protected
|
89
|
+
|
90
|
+
def card_offset
|
91
|
+
(card_number-1) * passcodes_per_card
|
92
|
+
end
|
69
93
|
end
|
70
94
|
end
|
71
95
|
end
|
data/lib/ppp/card/plain.rb
CHANGED
data/lib/ppp/version.rb
CHANGED