Class: TikaWrapper::Instance
- Inherits:
-
Object
- Object
- TikaWrapper::Instance
- Defined in:
- lib/tika_wrapper/instance.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#clean! ⇒ Object
Clean up any files tika_wrapper may have downloaded.
-
#initialize(options = {}) ⇒ Instance
constructor
A new instance of Instance.
-
#port ⇒ Object
Get the port this tika instance is running at.
-
#start ⇒ Object
Start tika and wait for it to become available.
-
#started? ⇒ Boolean
Is tika running?.
-
#status ⇒ Object
Check the status of a managed tika service.
-
#stop ⇒ Object
Stop tika and wait for it to finish exiting.
-
#url ⇒ Object
Get a (likely) URL to the tika instance.
- #wrap(&_block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Instance
Returns a new instance of Instance.
29 30 31 |
# File 'lib/tika_wrapper/instance.rb', line 29 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/tika_wrapper/instance.rb', line 12 def @options end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
12 13 14 |
# File 'lib/tika_wrapper/instance.rb', line 12 def pid @pid end |
Instance Method Details
#clean! ⇒ Object
Clean up any files tika_wrapper may have downloaded
96 97 98 99 100 |
# File 'lib/tika_wrapper/instance.rb', line 96 def clean! stop FileUtils.remove_entry(download_path) if File.exists? download_path FileUtils.remove_entry(md5sum_path) if File.exists? md5sum_path end |
#port ⇒ Object
Get the port this tika instance is running at
90 91 92 |
# File 'lib/tika_wrapper/instance.rb', line 90 def port .fetch(:port, "9998").to_s end |
#start ⇒ Object
Start tika and wait for it to become available
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tika_wrapper/instance.rb', line 42 def start download if managed? exec(p: port) # Wait for tika to start unless status sleep 1 end end end |
#started? ⇒ Boolean
Is tika running?
84 85 86 |
# File 'lib/tika_wrapper/instance.rb', line 84 def started? !!status end |
#status ⇒ Object
Check the status of a managed tika service
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tika_wrapper/instance.rb', line 71 def status return true unless managed? begin open(url + "version") true rescue false end end |
#stop ⇒ Object
Stop tika and wait for it to finish exiting
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tika_wrapper/instance.rb', line 56 def stop if managed? && started? Process.kill("KILL", pid.to_i) # Wait for tika to stop while status sleep 1 end end @pid = nil end |
#url ⇒ Object
Get a (likely) URL to the tika instance
104 105 106 |
# File 'lib/tika_wrapper/instance.rb', line 104 def url "http://127.0.0.1:#{port}/" end |
#wrap(&_block) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/tika_wrapper/instance.rb', line 33 def wrap(&_block) start yield self ensure stop end |