Class: RqrcodePngBin::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/rqrcode_png_bin/file_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileReader

Returns a new instance of FileReader.



5
6
7
8
9
10
11
# File 'lib/rqrcode_png_bin/file_reader.rb', line 5

def initialize(file)
  @file = open(file)
  @pat  = %r{\A([^\t]+)(?:\t([^\t]+))?\z}

  @str  = nil
  @dest = nil
end

Instance Method Details

#each(&block) ⇒ Object

param

Proc block



16
17
18
19
20
21
# File 'lib/rqrcode_png_bin/file_reader.rb', line 16

def each(&block)
  @file.each_line {|line|
    split!(line.chomp)
    block.call(@str, @dest)
  }
end

#split!(line) ⇒ Object

param

String line



26
27
28
29
30
31
# File 'lib/rqrcode_png_bin/file_reader.rb', line 26

def split!(line)
  @pat =~ line

  @str  = $1
  @dest = $2 ? $2 : "#{CGI.escape($1)}.png"
end