Class: Svgcode::CLI
- Inherits:
-
Thor
- Object
- Thor
- Svgcode::CLI
- Defined in:
- lib/svgcode/cli.rb
Constant Summary collapse
- DEFAULT_POST_URL =
'http://linux-cnc.bmo:8080'- DEFAULT_POST_NAME =
'file'
Instance Method Summary collapse
Instance Method Details
#parse(in_path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/svgcode/cli.rb', line 24 def parse(in_path) in_path = File.(in_path) raise "#{in_path} is not readable" unless File.readable?(in_path) svg_str = File.read(in_path) out_path = if [:out_path].nil? in_path.gsub(/\.svg\Z/i, '.ngc') else File.([:out_path]) end opts = { comments: [:comments] } File.open(out_path, 'w') { |f| f << Svgcode.parse(svg_str, opts) } puts "G-code written to #{out_path}" end |
#post(ngc_path) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/svgcode/cli.rb', line 57 def post(ngc_path) ngc_path = File.(ngc_path) raise "#{ngc_path} is not readable" unless File.readable?(ngc_path) uri = URI([:url]) request = Net::HTTP::Post.new(uri) form_data = [[[:post_name], File.open(ngc_path)]] = nil request.set_form form_data, 'multipart/form-data' response = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(request) end puts response puts "G-code posted to #{options[:url]}" end |