lib/yomu.rb in yomu-0.1.3 vs lib/yomu.rb in yomu-0.1.4

- old
+ new

@@ -10,20 +10,20 @@ # Read text or metadata from a data buffer. # # data = File.read 'sample.pages' # text = Yomu.read :text, data # metadata = Yomu.read :metadata, data - # + def self.read(type, data) switch = case type when :text '-t' when :metadata '-m' end - result = IO.popen "java -Djava.awt.headless=true -jar #{Yomu::JARPATH} #{switch}", 'r+' do |io| + result = IO.popen "#{java} -Djava.awt.headless=true -jar #{Yomu::JARPATH} #{switch}", 'r+' do |io| io.write data io.close_write io.read end @@ -41,11 +41,11 @@ # Yomu.new 'http://svn.apache.org/repos/asf/poi/trunk/test-data/document/sample.docx' # # From a stream or an object which responds to +read+ # # Yomu.new File.open('sample.pages') - # + def initialize(input) if input.is_a? String if input =~ URI::regexp @uri = URI.parse input elsif File.exists? input @@ -62,61 +62,61 @@ # Returns the text content of the Yomu document. # # yomu = Yomu.new 'sample.pages' # yomu.text - # + def text return @text if defined? @text @text = Yomu.read :text, data end # Returns the metadata hash of the Yomu document. # # yomu = Yomu.new 'sample.pages' # yomu.metadata['Content-Type'] - # + def metadata return @metadata if defined? @metadata @metadata = Yomu.read :metadata, data end # Returns +true+ if the Yomu document was specified using a file path. # # yomu = Yomu.new 'sample.pages' # yomu.path? #=> true - # + def path? defined? @path end # Returns +true+ if the Yomu document was specified using a URI. # # yomu = Yomu.new 'http://svn.apache.org/repos/asf/poi/trunk/test-data/document/sample.docx' # yomu.uri? #=> true - # + def uri? defined? @uri end # Returns +true+ if the Yomu document was specified from a stream or an object which responds to +read+. # # file = File.open('sample.pages') # yomu = Yomu.new file # yomu.stream? #=> true - # + def stream? defined? @stream end # Returns the raw/unparsed content of the Yomu document. # # yomu = Yomu.new 'sample.pages' # yomu.data - # + def data return @data if defined? @data if path? @data = File.read @path @@ -126,6 +126,11 @@ @data = @stream.read end @data end + + def self.java + ENV['JAVA_HOME'] ? ENV['JAVA_HOME'] + '/bin/java' : 'java' + end + private_class_method :java end