Skip to content

Commit

Permalink
chore: make helper functions private
Browse files Browse the repository at this point in the history
  • Loading branch information
yksflip committed Jul 2, 2024
1 parent 95aaa00 commit b078cfa
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ def row_classes(article)
classes.join(' ')
end

def format_unit(unit_property, article)
unit_code = article.send(unit_property)
return article.unit if unit_code.nil?

ArticleUnitsLib.human_readable_unit(unit_code)
end

def format_supplier_order_unit(article)
format_unit(:supplier_order_unit, article)
end
Expand All @@ -34,15 +27,6 @@ def format_billing_unit(article)
format_unit(:billing_unit, article)
end

def format_unit_with_ratios(unit_property, article_version, reference_unit = :group_order_unit)
base = format_unit(unit_property, article_version)

factorized_unit_str = get_factorized_unit_str(article_version, unit_property, reference_unit) unless reference_unit.nil?
return base if factorized_unit_str.nil?

"#{base} (#{factorized_unit_str})"
end

def format_supplier_order_unit_with_ratios(article)
format_unit_with_ratios(:supplier_order_unit, article)
end
Expand Down Expand Up @@ -72,6 +56,22 @@ def field_with_preset_value_and_errors(options)

private

def format_unit_with_ratios(unit_property, article_version, reference_unit = :group_order_unit)
base = format_unit(unit_property, article_version)

factorized_unit_str = get_factorized_unit_str(article_version, unit_property, reference_unit) unless reference_unit.nil?
return base if factorized_unit_str.nil?

"#{base} (#{factorized_unit_str})"
end

def format_unit(unit_property, article)
unit_code = article.send(unit_property)
return article.unit if unit_code.nil?

ArticleUnitsLib.human_readable_unit(unit_code)
end

def get_factorized_unit_str(article_version, unit_property, reference_unit)
unit_code = article_version.send(unit_property)
reference_unit_code = article_version.send(reference_unit) || article_version.supplier_order_unit
Expand Down

0 comments on commit b078cfa

Please sign in to comment.