Class: Clarifai::Rails::Detector
- Inherits:
-
Object
- Object
- Clarifai::Rails::Detector
- Defined in:
- lib/clarifai/rails/detector.rb
Instance Method Summary collapse
-
#error ⇒ Object
Status method.
- #error? ⇒ Boolean
- #image ⇒ Object
- #images ⇒ Object
-
#initialize(urls, opts = {}) ⇒ Detector
constructor
A new instance of Detector.
- #results ⇒ Object
- #success? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(urls, opts = {}) ⇒ Detector
Returns a new instance of Detector.
8 9 10 11 12 13 |
# File 'lib/clarifai/rails/detector.rb', line 8 def initialize(urls, opts={}) raise 'Input data not supported! (String Array or String only)' unless valid_params?(urls) @urls = urls.is_a?(Array) ? urls : [urls] @model_code = opts[:model] || Clarifai::Rails.model_code raise 'Model need to set' if @model_code.blank? end |
Instance Method Details
#error ⇒ Object
Status method
36 37 38 |
# File 'lib/clarifai/rails/detector.rb', line 36 def error Clarifai::Rails::Error.detector(to_hash[:status]) end |
#error? ⇒ Boolean
40 41 42 |
# File 'lib/clarifai/rails/detector.rb', line 40 def error? error.present? end |
#image ⇒ Object
30 31 32 |
# File 'lib/clarifai/rails/detector.rb', line 30 def image Clarifai::Rails::Image.new(results.first) end |
#images ⇒ Object
24 25 26 27 28 |
# File 'lib/clarifai/rails/detector.rb', line 24 def images results.map do |image| Clarifai::Rails::Image.new(image) end end |
#results ⇒ Object
20 21 22 |
# File 'lib/clarifai/rails/detector.rb', line 20 def results to_hash[:outputs] end |
#success? ⇒ Boolean
44 45 46 |
# File 'lib/clarifai/rails/detector.rb', line 44 def success? error.blank? end |
#to_hash ⇒ Object
15 16 17 18 |
# File 'lib/clarifai/rails/detector.rb', line 15 def to_hash @data_urls ||= fetch @data_urls.is_a?(Hash) ? @data_urls : JSON.parse(@data_urls).symbolize_keys end |