Class: Clarifai::Rails::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/clarifai/rails/detector.rb

Instance Method Summary collapse

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

#errorObject

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

Returns:

  • (Boolean)


40
41
42
# File 'lib/clarifai/rails/detector.rb', line 40

def error?
  error.present?
end

#imageObject



30
31
32
# File 'lib/clarifai/rails/detector.rb', line 30

def image
  Clarifai::Rails::Image.new(results.first)
end

#imagesObject



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

#resultsObject



20
21
22
# File 'lib/clarifai/rails/detector.rb', line 20

def results
  to_hash[:outputs]
end

#success?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/clarifai/rails/detector.rb', line 44

def success?
  error.blank?
end

#to_hashObject



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