dscf-marketplace 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57b94e7df1ac8fe6e08df594a8a5509a16b2b6383071208a636a8981a0a6618a
4
- data.tar.gz: 78f4ea4db87b33c9ad5027b40a710f5c5070a928c54f2fd3c351321c378d7ef5
3
+ metadata.gz: 796eeeaf3921a9ddb0e478285af2b644a972cb51a53231a39e7062e7c4b53f0a
4
+ data.tar.gz: af123ae47644fd07cca78b7e3b4907ef79d530cf96dff069338499ebf908cd0e
5
5
  SHA512:
6
- metadata.gz: b0b2b27060010f601b6469c685302927b20d6559d13af18fac98ca6abaf0212a255739c1010952f63aeac14033283199fcfee734fdc97fa81f4b8ccdfa301fa6
7
- data.tar.gz: 250396abdd9c4f188a0ecb7be10ff9a9c52aafccb0811201b7d923994b56f3fe2e892a6eb3d9a28261788f9dc04e1eb7e5173a7049c840c77b87b5f2924ced9b
6
+ metadata.gz: d6aa7f04ccb27eb52e027c68a72c429cfdf793d9c7dfde195851b868e6a69296e6328000eed13fd12075dd18ef76f164f6d7a8deee69a1dc31869f809c30da79
7
+ data.tar.gz: 9a4653a2bbd5b67779a5180ea2dc660971e50485ed6224d86f7904079bdc1302bd6c26bb2c8006761c22f43b9e0f5e335c15db9bbfff8ed6098b83f51a5b9fdc
@@ -30,10 +30,10 @@ module Dscf
30
30
 
31
31
  def convertible_to?(other_unit)
32
32
  return false if other_unit.nil?
33
+ return true if id == other_unit.id
33
34
 
34
- # NOTE: UnitConversion model not yet implemented
35
- # For now, return false - will be implemented when UnitConversion is created
36
- false
35
+ unit_conversions.exists?(to_unit: other_unit) ||
36
+ other_unit.unit_conversions.exists?(to_unit: self)
37
37
  end
38
38
  end
39
39
  end
@@ -0,0 +1,33 @@
1
+ module Dscf
2
+ module Marketplace
3
+ class UnitConversion < ApplicationRecord
4
+ belongs_to :from_unit, class_name: "Dscf::Marketplace::Unit"
5
+ belongs_to :to_unit, class_name: "Dscf::Marketplace::Unit"
6
+
7
+ validates :from_unit_id, presence: true
8
+ validates :to_unit_id, presence: true
9
+ validates :conversion_factor, presence: true, numericality: {greater_than: 0}
10
+ validates :notes, length: {maximum: 500}, allow_blank: true
11
+
12
+ validate :units_must_be_different
13
+
14
+ def units_must_be_different
15
+ return unless from_unit_id && to_unit_id
16
+
17
+ return unless from_unit_id == to_unit_id
18
+
19
+ errors.add(:to_unit_id, "must be different from from_unit")
20
+ end
21
+
22
+ def reverse_conversion_factor
23
+ return nil unless conversion_factor && conversion_factor != 0
24
+
25
+ 1.0 / conversion_factor
26
+ end
27
+
28
+ def description
29
+ "#{from_unit&.display_name} → #{to_unit&.display_name} (×#{conversion_factor})"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ class CreateDscfMarketplaceUnitConversions < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :dscf_marketplace_unit_conversions do |t|
4
+ t.references :from_unit,
5
+ index: {name: "from_unit_on_dm_uc_indx"},
6
+ null: false,
7
+ foreign_key: {to_table: :dscf_marketplace_units}
8
+ t.references :to_unit,
9
+ index: {name: "to_unit_on_dm_uc_indx"},
10
+ null: false,
11
+ foreign_key: {to_table: :dscf_marketplace_units}
12
+ t.decimal :conversion_factor, precision: 15, scale: 6, null: false
13
+ t.string :notes, limit: 500
14
+
15
+ t.timestamps
16
+ end
17
+
18
+ add_index :dscf_marketplace_unit_conversions,
19
+ %i[from_unit_id to_unit_id],
20
+ unique: true,
21
+ name: "unique_unit_conversion_indx"
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Marketplace
3
- VERSION = "0.1.2".freeze
3
+ VERSION = "0.1.3".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ FactoryBot.define do
2
+ factory :dscf_marketplace_unit_conversion, class: "Dscf::Marketplace::UnitConversion" do
3
+ from_unit { create(:dscf_marketplace_unit) }
4
+ to_unit { create(:dscf_marketplace_unit) }
5
+ conversion_factor { 1.5 }
6
+ notes { "Conversion factor description" }
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-marketplace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat
@@ -423,15 +423,18 @@ files:
423
423
  - app/models/dscf/marketplace/application_record.rb
424
424
  - app/models/dscf/marketplace/category.rb
425
425
  - app/models/dscf/marketplace/unit.rb
426
+ - app/models/dscf/marketplace/unit_conversion.rb
426
427
  - config/routes.rb
427
428
  - db/migrate/20250827172043_create_dscf_marketplace_categories.rb
428
429
  - db/migrate/20250827173526_update_dscf_marketplace_categories_indexes.rb
429
430
  - db/migrate/20250827182550_create_dscf_marketplace_units.rb
431
+ - db/migrate/20250827185656_create_dscf_marketplace_unit_conversions.rb
430
432
  - lib/dscf/marketplace.rb
431
433
  - lib/dscf/marketplace/engine.rb
432
434
  - lib/dscf/marketplace/version.rb
433
435
  - lib/tasks/dscf/marketplace_tasks.rake
434
436
  - spec/factories/dscf/marketplace/categories.rb
437
+ - spec/factories/dscf/marketplace/unit_conversions.rb
435
438
  - spec/factories/dscf/marketplace/units.rb
436
439
  homepage: https://mksaddis.com/
437
440
  licenses:
@@ -446,7 +449,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
446
449
  requirements:
447
450
  - - ">="
448
451
  - !ruby/object:Gem::Version
449
- version: '3.2'
452
+ version: '3.4'
450
453
  required_rubygems_version: !ruby/object:Gem::Requirement
451
454
  requirements:
452
455
  - - ">="