lib/unicoder/builder.rb in unicoder-1.1.1 vs lib/unicoder/builder.rb in unicoder-1.3.0

- old
+ new

@@ -71,11 +71,21 @@ filename.sub! /\A(https?|ftp):\//, "" Downloader.fetch(identifier) unless File.exist?(LOCAL_DATA_DIRECTORY + filename) file = File.read(LOCAL_DATA_DIRECTORY + filename) if parse_mode == :line + active = !parse_options[:begin] + file.each_line{ |line| - yield Hash[ $~.names.zip( $~.captures ) ] if line =~ parse_options[:regex] + if !active && parse_options[:begin] && line.match?(parse_options[:begin]) + active = true + elsif active && parse_options[:end] && line.match?(parse_options[:end]) + active = false + end + + if active + yield Hash[ $~.names.zip( $~.captures ) ] if line =~ parse_options[:regex] + end } elsif parse_mode == :xml require "oga" yield Oga.parse_xml(file) else