Class: Dscf::Marketplace::UnitConversion
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dscf::Marketplace::UnitConversion
- Defined in:
- app/models/dscf/marketplace/unit_conversion.rb
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
-
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration for secure filtering.
Instance Method Summary collapse
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
19 20 21 |
# File 'app/models/dscf/marketplace/unit_conversion.rb', line 19 def self.ransackable_associations(_auth_object = nil) %w[from_unit to_unit] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
Ransack configuration for secure filtering
15 16 17 |
# File 'app/models/dscf/marketplace/unit_conversion.rb', line 15 def self.ransackable_attributes(_auth_object = nil) %w[id from_unit_id to_unit_id conversion_factor notes created_at updated_at] end |
Instance Method Details
#description ⇒ Object
37 38 39 |
# File 'app/models/dscf/marketplace/unit_conversion.rb', line 37 def description "#{from_unit&.display_name} → #{to_unit&.display_name} (×#{conversion_factor})" end |
#reverse_conversion_factor ⇒ Object
31 32 33 34 35 |
# File 'app/models/dscf/marketplace/unit_conversion.rb', line 31 def reverse_conversion_factor return nil unless conversion_factor && conversion_factor != 0 1.0 / conversion_factor end |
#units_must_be_different ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/models/dscf/marketplace/unit_conversion.rb', line 23 def units_must_be_different return unless from_unit_id && to_unit_id return unless from_unit_id == to_unit_id errors.add(:to_unit_id, "must be different from from_unit") end |