Class: Convertible::Cli
- Inherits:
-
Object
- Object
- Convertible::Cli
- Defined in:
- lib/convertible/cli.rb
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(key, input, output = nil, options = {}) ⇒ Cli
constructor
A new instance of Cli.
- #show ⇒ Object
Constructor Details
#initialize(key, input, output = nil, options = {}) ⇒ Cli
Returns a new instance of Cli.
6 7 8 9 10 11 |
# File 'lib/convertible/cli.rb', line 6 def initialize(key, input, output = nil, = {}) @key = key @input = input @output = output @options = end |
Instance Method Details
#convert ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/convertible/cli.rb', line 13 def convert data = case @input when 'STDIN' $stdin.read when /^https?:\/\// URI.parse @input else File.read(@input) if File.readable?(@input) end raise ArgumentError, "cannot open #{@input} for reading" unless data check_mimetypes !(URI === data) $stderr.puts "converting #{@input} to #{@output} with options #{@options.inspect}" if @options[:debug] response = client.convert data, @input_type, @output_type, @options if @output == 'STDOUT' $stdout << response else (File.open(@output, 'wb') << response).close end end |
#show ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/convertible/cli.rb', line 35 def show check_mimetypes false, false if in_t = @input_type if out_t = @output_type if client.supported?(in_t, out_t) puts 'supported' else puts 'not supported' # no worky end else conversions = client.supported_conversions @input_type $stderr.puts "Supported output formats for #{@input_type}:" puts conversions.join(', ') end else conversions = client.supported_conversions $stderr.puts "Supported conversions:" conversions.keys.sort.each do |input| puts "#{input} => " << conversions[input].join(', ') end end end |