Class: ChupaText::Decomposers::WebKit::ExternalScreenshoter
- Inherits:
-
Object
- Object
- ChupaText::Decomposers::WebKit::ExternalScreenshoter
- Includes:
- LogTag, Loggable
- Defined in:
- lib/chupa-text/decomposers/webkit.rb
Instance Method Summary collapse
-
#initialize ⇒ ExternalScreenshoter
constructor
A new instance of ExternalScreenshoter.
- #run(html_path, uri, output_path, width, height) ⇒ Object
Constructor Details
#initialize ⇒ ExternalScreenshoter
Returns a new instance of ExternalScreenshoter.
92 93 94 95 96 97 98 99 100 |
# File 'lib/chupa-text/decomposers/webkit.rb', line 92 def initialize @screenshoter = File.join(__dir__, "..", "..", "..", "bin", "chupa-text-decomposer-webkit-screenshoter") @command = ExternalCommand.new(RbConfig.ruby) end |
Instance Method Details
#run(html_path, uri, output_path, width, height) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/chupa-text/decomposers/webkit.rb', line 102 def run(html_path, uri, output_path, width, height) output_read, output_write = IO.pipe error_output = Tempfile.new("chupa-text-decomposer-webkit-error") output_reader = Thread.new do loop do IO.select([output_read]) line = output_read.gets break if line.nil? case line.chomp when /\Adebug: / debug($POSTMATCH) when /\Aerror: / error($POSTMATCH) end end end successed = @command.run(@screenshoter, html_path, uri, output_path, width.to_s, height.to_s, { :spawn_options => { :out => output_write, :err => error_output.path, }, }) output_write.close output_reader.join unless successed error do = "failed to external screenshoter: #{uri}: " << "#{@command.path} #{@screenshoter}" "#{log_tag}[external-screenshoter][run][failed] #{}" end end unless error_output.size.zero? error_output.each_line do |line| error(line) end end end |