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.
@@ -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 = %[Expected a string with exactly one digit and one letter, got "%s".]
13
- @@ERROR_LONG_CODES = %[Passcodes longer than 16 characters are too long for printing]
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
- puts "offset: #{offset}"
50
- @generator.passcodes( offset, passcodes_per_line )
49
+
50
+ @generator.passcodes offset, passcodes_per_line
51
51
  end
52
52
  end
53
53
 
54
- def passcode row_col
55
- raise ArgumentError.new( @@ERROR_BAD_ROW_COL % row_col ) unless row_col.size == 2 && @@ROW_COL_PATTERN.match( row_col.split('').sort.join )
56
- passcode *row_col.split('')
57
- end
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
- @generator.passcode row_offset * passcodes_per_line + col_offset
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
@@ -71,7 +71,7 @@ class Ppp::Card::Plain < Ppp::Card::Base
71
71
  end
72
72
 
73
73
  def first_column row_index
74
- label = "#{row_index}:"
74
+ label = row_label row_index
75
75
  padding = ' ' * (first_column_width - label.size)
76
76
  padding + label
77
77
  end
@@ -1,3 +1,3 @@
1
1
  module Ppp
2
- VERSION = '0.1.5.alpha'
2
+ VERSION = '0.1.6.alpha'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.alpha
4
+ version: 0.1.6.alpha
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: