lib/yomu.rb in yomu-0.1.1 vs lib/yomu.rb in yomu-0.1.2

- old
+ new

@@ -3,11 +3,11 @@ require 'net/http' require 'yaml' class Yomu GEMPATH = File.dirname(File.dirname(__FILE__)) - JARPATH = File.join(Yomu::GEMPATH, 'jar', 'tika-app-1.1.jar') + JARPATH = File.join(Yomu::GEMPATH, 'jar', 'tika-app-1.2.jar') # Read text or metadata from a data buffer. # # data = File.read 'sample.pages' # text = Yomu.read :text, data @@ -28,21 +28,21 @@ end type == :metadata ? YAML.load(result) : result end - # Create a new instance of Yomu. + # Create a new instance of Yomu with a given document. # # Using a file path: # # Yomu.new 'sample.pages' # # Using a URL: # # Yomu.new 'http://svn.apache.org/repos/asf/poi/trunk/test-data/document/sample.docx' # - # Using a stream or object which responds to +read+ + # From a stream or an object which responds to +read+ # # Yomu.new File.open('sample.pages') def initialize(input) if input.is_a? String @@ -58,45 +58,64 @@ else raise TypeError.new "can't read from #{input.class.name}" end end - # Returns the text contents of a Yomu object. + # 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 a Yomu object. + # 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 - protected + # 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? @@ -107,6 +126,6 @@ @data = @stream.read end @data end -end \ No newline at end of file +end