Class: RabbitViewer::Command::RabbitViewer

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbit_viewer/command/rabbit_viewer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRabbitViewer

Returns a new instance of RabbitViewer.



17
18
# File 'lib/rabbit_viewer/command/rabbit_viewer.rb', line 17

def initialize
end

Class Method Details

.run(*arguments) ⇒ Object



12
13
14
# File 'lib/rabbit_viewer/command/rabbit_viewer.rb', line 12

def run(*arguments)
  new.run(arguments)
end

Instance Method Details

#run(arguments) ⇒ Object



20
21
22
23
24
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
54
55
# File 'lib/rabbit_viewer/command/rabbit_viewer.rb', line 20

def run(arguments)
  Tempfile.open(["rabbit_viewer", ".rab"]) do |tempfile|
    tempfile.puts(title)
  
    arguments.each do |viewfile_relative|
      viewfile = File.expand_path(viewfile_relative)
      next unless File.file?(viewfile)

      if Rabbit::VERSION <= "2.0.6"
        begin
          URI.parse(viewfile)
        rescue URI::InvalidURIError
          STDERR.puts($!.message)
          STDERR.puts("Support multibyte file path by Rabbit 2.0.7. Encourage update!")
          next
        end
      end

      case viewfile
      when /\.(svg|png|jpe?g|gif|eps|dia|xcf)$/i
        page = image_page(viewfile)
      else
        page = text_page(viewfile)
      end

      unless page
        page = undefind_page(viewfile)
      end

      tempfile.puts(page)
    end
  
    tempfile.flush
    Rabbit::Command::Rabbit.run(tempfile.path)
  end
end