Transform 7-segment display pattern into number Given A and B, where A is the scale of a Digital LED Pattern B. Parse pattern B and print the number.

input:

1
 _  _  _  _     _     _     _  _  _  _  _     _ 
 _| _| _|| ||_||_   ||_ |_|| |  ||_||_||_   ||_|
|_  _||_ |_|  | _|  ||_|  ||_|  |  |  | _|  ||_|


output:

2320451640799518


input:

2
 __  __
   |   | 
 __| __|
|      |
|__  __|


output:

23


Rules:


Use STDIN/STDOUT for input/output
I tried to mimic this question as much as possible, but I think code-golf suits this one better.
Shortest code (in bytes) wins
Ruby, 151 characters

s,*r=*$&lt;;c=r[s=s.to_i]
i=0;(n=(r[0][i+1]+c[i]+c[i+s,2]+r[-1][i]).tr(" |_","01").to_i 2
$&gt;&lt;&lt;(0..9).find{|j|0x3df9778eb5c5b&gt;&gt;5*j&amp;31==n};i+=s+2)while b[i]


Leaves out digits it cannot recognise, but some invalid digits are recognised nevertheless.

Assumes the lines are padded with spaces to their full length.