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.



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