Module: CapCap
- Defined in:
- lib/cap_cap.rb,
lib/cap_cap/version.rb
Defined Under Namespace
Classes: Main
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Class Method Details
.run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cap_cap.rb', line 25 def CapCap.run opts = {headers: []} opt = OptionParser.new opt. = "Usage: capcap [options] <url> [<url>...]" opt.on("-o", "--output=VAL", "Output capturing image to specific path. If ommited, output to tempfile.") {|v| opts[:output] = v } opt.on("-s", "--selector=VAL", "Capture only element specified by css selector. If ommited, capture entire page.") {|v| opts[:selector] = v } opt.on("-H", "--header=VAL", "Add extra HTTP-header to use when getting a web page.") {|v| opts[:headers] << v } opt.on("--size=VAL", "Specify rendering page size. If ommited, it may be default size. e.g., `--size 320x480`") {|v| opts[:size] = v.split(?x).map(&:to_i) } opt.on("--open", "If specified, invoke `open` command to preview captured image.") {|v| opts[:invoke_open] = v } opt.parse! ARGV main = Main.new main.resize *opts[:size] unless opts[:size].nil? if opts[:headers].size > 0 main.add_headers Hash[opts[:headers].map {|v| v.split(?:).map{|kv| kv.strip } }] end if ARGV.empty? puts opt.help exit elsif ARGV.size == 1 output = main.capture ARGV.first, opts[:output], selector: opts[:selector] main.invoke_open output if opts[:invoke_open] else outputs = ARGV.map {|url| main.capture url, selector: opts[:selector] } output = main.capture_combined outputs, opts[:output] main.invoke_open output if opts[:invoke_open] end end |