Sha256: dd1c122936c79cb8bca2111e8c03c02a06a515ed49423f795ca87b21c40e3c0a

Contents?: true

Size: 635 Bytes

Versions: 2

Compression:

Stored size: 635 Bytes

Contents

require "csv"

format :csv  do
  def default_nest_view
    :core
  end

  def default_item_view
    @depth.zero? ? :csv_row : :name
  end

  view :csv_row do
    array = _render_raw.scan(/\{\{[^\}]*\}\}/).map do |inc|
      process_content(inc).strip
    end

    CSV.generate_line(array).strip
    # strip is because search already joins with newlines
  end

  view :missing do |_args|
    ""
  end

  view :name_with_fields do
    CSV.generate_line name_with_fields_row
  end

  def name_with_fields_row
    nested_fields.each_with_object([card.name]) do |(field_name, _options), row|
      row << nest(field_name)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
card-1.91 mod/basic_formats/set/all/all_csv.rb
card-1.21.0 mod/basic_formats/set/all/all_csv.rb