mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
style updates for rubocop
This commit is contained in:
@@ -65,15 +65,15 @@ module OpenFoodNetwork
|
||||
def scale_for_unit_value
|
||||
units = {
|
||||
'weight' => {
|
||||
1.0 => { 'name' => 'g', 'system' => 'metric' },
|
||||
28.34952 => { 'name' => 'oz', 'system' => 'imperial' },
|
||||
453.6 => { 'name' => 'lb', 'system' => 'imperial' },
|
||||
1000.0 => { 'name' => 'kg', 'system' => 'metric' },
|
||||
1.0 => { 'name' => 'g', 'system' => 'metric' },
|
||||
28.34952 => { 'name' => 'oz', 'system' => 'imperial' },
|
||||
453.6 => { 'name' => 'lb', 'system' => 'imperial' },
|
||||
1000.0 => { 'name' => 'kg', 'system' => 'metric' },
|
||||
1_000_000.0 => { 'name' => 'T', 'system' => 'metric' }
|
||||
},
|
||||
'volume' => {
|
||||
0.001 => { 'name' => 'mL', 'system' => 'metric' },
|
||||
1.0 => { 'name' => 'L', 'system' => 'metric' },
|
||||
0.001 => { 'name' => 'mL', 'system' => 'metric' },
|
||||
1.0 => { 'name' => 'L', 'system' => 'metric' },
|
||||
1000.0 => { 'name' => 'kL', 'system' => 'metric' }
|
||||
}
|
||||
}
|
||||
@@ -86,8 +86,8 @@ module OpenFoodNetwork
|
||||
product_scale_system = scales[product_scale.to_f]['system']
|
||||
largest_unit = scales.select { |scale, unit_info|
|
||||
unit_info['system'] == product_scale_system &&
|
||||
@variant.unit_value/scale >= 1
|
||||
}.sort.last
|
||||
@variant.unit_value / scale >= 1
|
||||
}.max
|
||||
largest_unit = units[@variant.product.variant_unit].first if largest_unit.nil?
|
||||
|
||||
[largest_unit[0], largest_unit[1]["name"]]
|
||||
|
||||
@@ -18,14 +18,17 @@ module OpenFoodNetwork
|
||||
order("#{Spree::OptionType.table_name}.position asc")
|
||||
end
|
||||
|
||||
values.map { |option_value| presentation(option_value) }.to_sentence(words_connector: ", ", two_words_connector: ", ")
|
||||
values.map { |option_value|
|
||||
presentation(option_value)
|
||||
}.to_sentence(words_connector: ", ", two_words_connector: ", ")
|
||||
end
|
||||
|
||||
def presentation(option_value)
|
||||
if option_value.option_type.name == "unit_weight"
|
||||
if has_attribute?(:display_as) && display_as.present?
|
||||
return display_as
|
||||
elsif respond_to?(:variant) && variant.present? && variant.respond_to?(:display_as) && variant.display_as.present?
|
||||
elsif respond_to?(:variant) && variant.present? &&
|
||||
variant.respond_to?(:display_as) && variant.display_as.present?
|
||||
return variant.display_as
|
||||
end
|
||||
end
|
||||
@@ -61,7 +64,8 @@ module OpenFoodNetwork
|
||||
def unit_to_display
|
||||
if has_attribute?(:display_as) && display_as.present?
|
||||
display_as
|
||||
elsif respond_to?(:variant) && variant.present? && variant.respond_to?(:display_as) && variant.display_as.present?
|
||||
elsif respond_to?(:variant) && variant.present? &&
|
||||
variant.respond_to?(:display_as) && variant.display_as.present?
|
||||
variant.display_as
|
||||
else
|
||||
options_text
|
||||
|
||||
Reference in New Issue
Block a user