Sha256: f07c7611e972d8997cc75d873110ecead5bd13431fbf886ba2f8a0cff75aaec6

Contents?: true

Size: 1.11 KB

Versions: 14

Compression:

Stored size: 1.11 KB

Contents

require 'csv'

format :csv  do
  def get_inclusion_defaults
    { :view => :core }
  end
  
  def default_item_view 
    @depth == 0 ? :csv_row : :name
  end

  
  view :csv_row do |args|
    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 :csv_title_row do |args|
    #NOTE: assumes all cards have the same structure!
    begin
      card1 = search_vars[:results].first  
    
      parsed_content = Card::Content.new card1.raw_content, self
      unless String === parsed_content.__getobj__
        titles = parsed_content.map do |chunk|
          next if chunk.class != Card::Chunk::Include
          opts = chunk.options
          if ['name','link'].member? opts[:view]
            opts[:view]
          else
            opts[:inc_name].to_name.tag
          end
        end.compact.map {|title| title.to_s.upcase }
        CSV.generate_line titles
        
      else
        ''
      end
    rescue
      ''
    end
  end

end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
card-1.15.pre mod/02_basic_types/set/all/all_csv.rb
wagn-1.14.9 mod/02_basic_types/set/all/all_csv.rb
wagn-1.14.8 mod/02_basic_types/set/all/all_csv.rb
wagn-1.14.7 mod/02_basic_types/set/all/all_csv.rb
wagn-1.14.6 mod/05_standard/set/all/all_csv.rb
wagn-1.14.5 mod/05_standard/set/all/all_csv.rb
wagn-1.14.4 mod/05_standard/set/all/all_csv.rb
wagn-1.14.3 mod/05_standard/set/all/all_csv.rb
wagn-1.14.2 mod/05_standard/set/all/all_csv.rb
wagn-1.14.1 mod/05_standard/set/all/all_csv.rb
wagn-1.14.0 mod/05_standard/set/all/all_csv.rb
wagn-1.14.0.pre3 mod/05_standard/set/all/all_csv.rb
wagn-1.14.0.pre2 mod/05_standard/set/all/all_csv.rb
wagn-1.14.0.pre1 mod/05_standard/set/all/all_csv.rb