Class: RqrcodePngBin::FileReader
- Inherits:
-
Object
- Object
- RqrcodePngBin::FileReader
- Defined in:
- lib/rqrcode_png_bin/file_reader.rb
Instance Method Summary collapse
-
#each(&block) ⇒ Object
- param
-
Proc block.
-
#initialize(file) ⇒ FileReader
constructor
A new instance of FileReader.
-
#split!(line) ⇒ Object
- param
-
String line.
Constructor Details
#initialize(file) ⇒ FileReader
Returns a new instance of FileReader.
3 4 5 6 7 8 9 |
# File 'lib/rqrcode_png_bin/file_reader.rb', line 3 def initialize(file) @file = open(file, 'r:utf-8') @pat = %r{\A([^\t]+)(?:\t([^\t]+))?\z} @str = nil @dest = nil end |
Instance Method Details
#each(&block) ⇒ Object
- param
-
Proc block
14 15 16 17 18 19 |
# File 'lib/rqrcode_png_bin/file_reader.rb', line 14 def each(&block) @file.each_line {|line| split!(line.chomp) block.call(@str, @dest) if @str and @dest } end |
#split!(line) ⇒ Object
- param
-
String line
24 25 26 27 28 29 |
# File 'lib/rqrcode_png_bin/file_reader.rb', line 24 def split!(line) @pat =~ line @str = $1 @dest = $2 ? $2 : "#{$1.gsub(/\//, '%2F')}.png" if $1 end |