Class: ArticlesCsv

Inherits:
RenderCsv show all
Includes:
ApplicationHelper
Defined in:
lib/articles_csv.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#base_errors, #bootstrap_flash_patched, #close_button, #expand, #foodcoop_css_path, #foodcoop_css_tag, #format_currency, #format_date, #format_datetime, #format_datetime_timespec, #format_iban, #format_number, #format_roles, #format_time, #heading_helper, #icon, #items_per_page, #link_to_gmaps, #link_to_top, #pagination_links_remote, #remote_link_to, #show_title?, #show_user, #show_user_link, #sort_link_helper, #tab_is_active?, #title, #truncate, #weekday

Methods included from PathHelper

#finance_group_transactions_path

Methods inherited from RenderCsv

#initialize, #number_to_currency, #to_csv

Constructor Details

This class inherits a constructor from RenderCsv

Instance Method Details

#dataObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/articles_csv.rb', line 28

def data
  @object.each do |article|
    yield [
      article.availability ? I18n.t('simple_form.yes') : I18n.t('simple_form.no'),
      article.order_number,
      article.name,
      ArticleUnitsLib.get_translated_name_for_code(article.supplier_order_unit),
      article.unit,
      get_csv_ratios(article),
      article.minimum_order_quantity,
      ArticleUnitsLib.get_translated_name_for_code(article.billing_unit),
      article.group_order_granularity,
      ArticleUnitsLib.get_translated_name_for_code(article.group_order_unit),
      article.price_unit_price,
      ArticleUnitsLib.get_translated_name_for_code(article.price_unit),
      article.tax,
      article.deposit,
      article.note,
      article..try(:name),
      article.origin,
      article.manufacturer,
      article.id
    ]
  end
end

#escape_csv_ratio(str) ⇒ Object



63
64
65
# File 'lib/articles_csv.rb', line 63

def escape_csv_ratio(str)
  str.gsub('\\', '\\\\').gsub(',', '\\,')
end

#get_csv_ratios(article) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/articles_csv.rb', line 54

def get_csv_ratios(article)
  previous_quantity = nil
  article.article_unit_ratios.each_with_index.map do |ratio, _index|
    quantity = previous_quantity.nil? ? ratio.quantity : ratio.quantity / previous_quantity
    previous_quantity = ratio.quantity
    "#{quantity} #{escape_csv_ratio(ArticleUnitsLib.get_translated_name_for_code(ratio.unit))}"
  end.join(', ')
end

#headerObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/articles_csv.rb', line 4

def header
  [
    Article.human_attribute_name(:availability_short),
    Article.human_attribute_name(:order_number),
    Article.human_attribute_name(:name),
    Article.human_attribute_name(:supplier_order_unit),
    Article.human_attribute_name(:custom_unit),
    Article.human_attribute_name(:ratios_to_supplier_order_unit),
    Article.human_attribute_name(:minimum_order_quantity),
    Article.human_attribute_name(:billing_unit),
    Article.human_attribute_name(:group_order_granularity),
    Article.human_attribute_name(:group_order_unit),
    Article.human_attribute_name(:price),
    Article.human_attribute_name(:price_unit),
    Article.human_attribute_name(:tax),
    Article.human_attribute_name(:deposit),
    Article.human_attribute_name(:note),
    Article.human_attribute_name(:article_category),
    Article.human_attribute_name(:origin),
    Article.human_attribute_name(:manufacturer),
    @options[:foodsoft_url]
  ]
end