Class: Redmine::Export::CSV::Base

Inherits:
CSV
  • Object
show all
Includes:
I18n
Defined in:
lib/redmine/export/csv.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Class Method Details

.generate(options = {}, &block) ⇒ Object

Since:

  • 3.1.0



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/redmine/export/csv.rb', line 34

def generate(options = {}, &block)
  col_sep = l(:general_csv_separator)
  encoding = Encoding.find(options[:encoding]) rescue Encoding.find(l(:general_csv_encoding))

  str = ''.force_encoding(encoding)
  if encoding == Encoding::UTF_8
    # BOM
    str = "\xEF\xBB\xBF".force_encoding(encoding)
  end

  super(str, :col_sep => col_sep, :encoding => encoding, &block)
end

Instance Method Details

#<<(row) ⇒ Object

Since:

  • 3.1.0



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/redmine/export/csv.rb', line 48

def <<(row)
  row = row.map do |field|
    case field
    when String
      Redmine::CodesetUtil.from_utf8(field, self.encoding.name)
    when Float
      @decimal_separator ||= l(:general_csv_decimal_separator)
      ("%.2f" % field).gsub('.', @decimal_separator)
    else
      field
    end
  end
  super row
end