Class: Logistics::Core::WeightRange

Inherits:
ApplicationRecord show all
Defined in:
app/models/logistics/core/weight_range.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

as_json

Class Method Details

.check_range_overlap(weight_range) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'app/models/logistics/core/weight_range.rb', line 23

def self.check_range_overlap weight_range
  weight_ranges = WeightRange.all
  overlap = false
  weight_ranges.each do |we_range|
    if (weight_range.weight_from..weight_range.weight_to).overlaps?(we_range.weight_from..we_range.weight_to)
      overlap = true
    end
  end
  return overlap
end

.check_range_overlap_update(weight_range, id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/logistics/core/weight_range.rb', line 34

def self.check_range_overlap_update weight_range, id
  weight_ranges = WeightRange.all
  result = { 'overlap' => false, 'id' => 0 }
  weight_ranges.each do |we_range|
    if (weight_range.weight_from..weight_range.weight_to).overlaps?(we_range.weight_from..we_range.weight_to)
      if we_range.id != id.to_i
        result['overlap'] = true
        result['id'] = we_range.id
      end
    end
  end
  return result
end

.fetch_allObject



12
13
14
15
16
17
18
19
20
21
# File 'app/models/logistics/core/weight_range.rb', line 12

def self.fetch_all
  result = []
  WeightRange.all.each do |weight_range|
    result.push({id: weight_range.id,
                 weight_from: weight_range.weight_from,
                 weight_to:weight_range.weight_to,
                 weight_range_name: weight_range.weight_range_name})
  end
  return result
end

Instance Method Details

#weight_range_nameObject



8
9
10
# File 'app/models/logistics/core/weight_range.rb', line 8

def weight_range_name
  self.weight_from.to_s + ' - ' + self.weight_to.to_s
end