mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-26 18:56:06 -04:00
Rubocop compliance for harvest model
This commit is contained in:
@@ -60,7 +60,6 @@ Lint/Void:
|
||||
# Cop supports --auto-correct.
|
||||
Performance/StringReplacement:
|
||||
Exclude:
|
||||
- 'app/models/harvest.rb'
|
||||
- 'app/models/planting.rb'
|
||||
- 'app/models/seed.rb'
|
||||
- 'spec/rails_helper.rb'
|
||||
@@ -85,7 +84,6 @@ Rails/Date:
|
||||
Rails/HasAndBelongsToMany:
|
||||
Exclude:
|
||||
- 'app/models/crop.rb'
|
||||
- 'app/models/harvest.rb'
|
||||
- 'app/models/member.rb'
|
||||
- 'app/models/photo.rb'
|
||||
- 'app/models/planting.rb'
|
||||
@@ -291,7 +289,6 @@ Style/IdenticalConditionalBranches:
|
||||
# Offense count: 1
|
||||
Style/IfInsideElse:
|
||||
Exclude:
|
||||
- 'app/models/harvest.rb'
|
||||
|
||||
# Offense count: 26
|
||||
# Cop supports --auto-correct.
|
||||
@@ -302,7 +299,6 @@ Style/IfUnlessModifier:
|
||||
- 'app/controllers/shop_controller.rb'
|
||||
- 'app/helpers/crops_helper.rb'
|
||||
- 'app/models/crop.rb'
|
||||
- 'app/models/harvest.rb'
|
||||
- 'app/models/member.rb'
|
||||
- 'app/models/order.rb'
|
||||
- 'app/models/planting.rb'
|
||||
@@ -352,7 +348,6 @@ Style/MultilineBlockLayout:
|
||||
# SupportedStyles: symmetrical, new_line, same_line
|
||||
Style/MultilineHashBraceLayout:
|
||||
Exclude:
|
||||
- 'app/models/harvest.rb'
|
||||
- 'app/models/planting.rb'
|
||||
- 'app/models/product.rb'
|
||||
- 'app/models/seed.rb'
|
||||
@@ -432,7 +427,6 @@ Style/MultilineTernaryOperator:
|
||||
Style/MutableConstant:
|
||||
Exclude:
|
||||
- 'app/controllers/members_controller.rb'
|
||||
- 'app/models/harvest.rb'
|
||||
- 'app/models/planting.rb'
|
||||
- 'app/models/seed.rb'
|
||||
|
||||
@@ -471,7 +465,6 @@ Style/NilComparison:
|
||||
# Configuration parameters: IncludeSemanticChanges.
|
||||
Style/NonNilCheck:
|
||||
Exclude:
|
||||
- 'app/models/harvest.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# Cop supports --auto-correct.
|
||||
@@ -497,7 +490,6 @@ Style/NumericPredicate:
|
||||
- 'app/helpers/harvests_helper.rb'
|
||||
- 'app/helpers/plantings_helper.rb'
|
||||
- 'app/models/crop.rb'
|
||||
- 'app/models/harvest.rb'
|
||||
- 'app/models/photo.rb'
|
||||
- 'lib/tasks/growstuff.rake'
|
||||
- 'script/check_contributors_md'
|
||||
@@ -565,7 +557,6 @@ Style/RedundantSelf:
|
||||
- 'app/models/comment.rb'
|
||||
- 'app/models/crop.rb'
|
||||
- 'app/models/follow.rb'
|
||||
- 'app/models/harvest.rb'
|
||||
- 'app/models/member.rb'
|
||||
- 'app/models/notification.rb'
|
||||
- 'app/models/order.rb'
|
||||
@@ -619,7 +610,6 @@ Style/SymbolProc:
|
||||
Exclude:
|
||||
- 'app/controllers/crops_controller.rb'
|
||||
- 'app/models/crop.rb'
|
||||
- 'app/models/harvest.rb'
|
||||
- 'app/models/planting.rb'
|
||||
- 'app/models/post.rb'
|
||||
- 'lib/tasks/growstuff.rake'
|
||||
@@ -664,7 +654,6 @@ Style/UnlessElse:
|
||||
Style/UnneededInterpolation:
|
||||
Exclude:
|
||||
- 'app/models/crop.rb'
|
||||
- 'app/models/harvest.rb'
|
||||
- 'spec/features/crops/crop_wranglers_spec.rb'
|
||||
- 'spec/features/following_spec.rb'
|
||||
- 'spec/features/shared_examples/append_date.rb'
|
||||
|
||||
@@ -20,7 +20,8 @@ class Harvest < ActiveRecord::Base
|
||||
validates :quantity,
|
||||
numericality: {
|
||||
only_integer: false,
|
||||
greater_than_or_equal_to: 0 },
|
||||
greater_than_or_equal_to: 0
|
||||
},
|
||||
allow_nil: true
|
||||
|
||||
UNITS_VALUES = {
|
||||
@@ -34,7 +35,7 @@ class Harvest < ActiveRecord::Base
|
||||
"buckets" => "bucket",
|
||||
"baskets" => "basket",
|
||||
"bushels" => "bushel"
|
||||
}
|
||||
}.freeze
|
||||
validates :unit, inclusion: { in: UNITS_VALUES.values,
|
||||
message: "%{value} is not a valid unit" },
|
||||
allow_nil: true,
|
||||
@@ -48,7 +49,7 @@ class Harvest < ActiveRecord::Base
|
||||
"kg" => "kg",
|
||||
"lb" => "lb",
|
||||
"oz" => "oz"
|
||||
}
|
||||
}.freeze
|
||||
validates :weight_unit, inclusion: { in: WEIGHT_UNITS_VALUES.values,
|
||||
message: "%{value} is not a valid unit" },
|
||||
allow_nil: true,
|
||||
@@ -61,20 +62,20 @@ class Harvest < ActiveRecord::Base
|
||||
# we're storing the harvest weight in kilograms in the db too
|
||||
# to make data manipulation easier
|
||||
def set_si_weight
|
||||
return if self.weight_unit.nil?
|
||||
weight_string = "#{self.weight_quantity} #{self.weight_unit}"
|
||||
return if weight_unit.nil?
|
||||
weight_string = "#{weight_quantity} #{weight_unit}"
|
||||
self.si_weight = Unit.new(weight_string).convert_to("kg").to_s("%0.3f").delete(" kg").to_f
|
||||
end
|
||||
|
||||
def cleanup_quantities
|
||||
self.quantity = nil if quantity == 0
|
||||
self.quantity = nil if quantity.zero?
|
||||
self.unit = nil if quantity.blank?
|
||||
self.weight_quantity = nil if weight_quantity == 0
|
||||
self.weight_quantity = nil if weight_quantity.zero?
|
||||
self.weight_unit = nil if weight_quantity.blank?
|
||||
end
|
||||
|
||||
def harvest_slug
|
||||
"#{owner.login_name}-#{crop}".downcase.gsub(' ', '-')
|
||||
"#{owner.login_name}-#{crop}".downcase.tr(' ', '-')
|
||||
end
|
||||
|
||||
# stringify as "beet in Skud's backyard" or similar
|
||||
@@ -82,28 +83,28 @@ class Harvest < ActiveRecord::Base
|
||||
# 50 individual apples, weighing 3lb
|
||||
# 2 buckets of apricots, weighing 10kg
|
||||
string = ''
|
||||
if self.quantity
|
||||
string += "#{number_to_human(self.quantity.to_s, strip_insignificant_zeros: true)} "
|
||||
string += if self.unit == 'individual'
|
||||
if quantity
|
||||
string += "#{number_to_human(quantity.to_s, strip_insignificant_zeros: true)} "
|
||||
string += if unit == 'individual'
|
||||
'individual '
|
||||
elsif self.quantity == 1
|
||||
"#{self.unit} of "
|
||||
elsif quantity == 1
|
||||
"#{unit} of "
|
||||
else
|
||||
"#{self.unit.pluralize} of "
|
||||
"#{unit.pluralize} of "
|
||||
end
|
||||
end
|
||||
|
||||
string += if self.unit != 'individual' # buckets of apricot*s*
|
||||
"#{self.crop.name.pluralize}"
|
||||
elsif self.quantity == 1
|
||||
"#{self.crop.name}"
|
||||
string += if unit != 'individual' # buckets of apricot*s*
|
||||
crop.name.pluralize.to_s
|
||||
elsif quantity == 1
|
||||
crop.name.to_s
|
||||
else
|
||||
"#{self.crop.name.pluralize}"
|
||||
crop.name.pluralize.to_s
|
||||
end
|
||||
|
||||
if self.weight_quantity
|
||||
string += " weighing #{number_to_human(self.weight_quantity, strip_insignificant_zeros: true)}"\
|
||||
" #{self.weight_unit}"
|
||||
if weight_quantity
|
||||
string += " weighing #{number_to_human(weight_quantity, strip_insignificant_zeros: true)}"\
|
||||
" #{weight_unit}"
|
||||
end
|
||||
|
||||
string
|
||||
|
||||
Reference in New Issue
Block a user