Module: FeatherAi::Rails::ActsAsSighting::InstanceMethods

Defined in:
lib/feather_ai/rails/acts_as_sighting.rb

Overview

Instance methods for bird sighting records.

Instance Method Summary collapse

Instance Method Details

#correct!(attrs) ⇒ Object



26
27
28
29
30
31
# File 'lib/feather_ai/rails/acts_as_sighting.rb', line 26

def correct!(attrs)
  return if attrs.empty?

  validate_correctable_fields!(attrs.keys)
  update!(prefix_and_timestamp_attrs(attrs))
end

#corrected?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/feather_ai/rails/acts_as_sighting.rb', line 69

def corrected?
  !corrected_at.nil?
end

#correction_deltaObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/feather_ai/rails/acts_as_sighting.rb', line 73

def correction_delta
  return {} unless corrected?

  CORRECTABLE_FIELDS.each_with_object({}) do |field, delta|
    corrected_value = public_send(:"corrected_#{field}")
    next if corrected_value.nil?

    # NOTE: `public_send(field)` reads the original AI column, not the
    # corrected column, so :from always reflects the AI identification
    # regardless of how many times correct! has been called.
    delta[field] = { from: public_send(field), to: corrected_value }
  end
end

#identify!Object



17
18
19
20
21
22
23
24
# File 'lib/feather_ai/rails/acts_as_sighting.rb', line 17

def identify!
  photo_file = photo.download
  result = FeatherAi.identify(photo_file, location: location)
  update_from_result!(result)
  result
ensure
  close_photo_file(photo_file)
end