Module: Card::Set::All::Csv::CsvFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
card/tmpsets/set/mod008-card-mod-format/all/csv.rb,
card/tmpsets/set/mod007-card-mod-format/all/csv.rb

Instance Method Summary collapse

Instance Method Details

#column_title(opts) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 91

def column_title opts
  if opts[:title]
    opts[:title]
  elsif %w[name link].member? opts[:view]
    opts[:view]
  else
    opts[:nest_name].to_name.tag
  end
end

#column_titles(extra_titles = nil) ⇒ Object



82
83
84
85
86
87
88
89
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 82

def column_titles extra_titles=nil
  res = Array extra_titles
  card1 = Card.fetch card.item_names(limit: 1).first
  card1.nest_chunks.each do |chunk|
    res << column_title(chunk.options)
  end
  res.compact
end

#columnsObject



62
63
64
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 62

def columns
  csv_structure_card.format.nested_field_names.map(&:tag)
end

#csv_structure_cardObject



66
67
68
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 66

def csv_structure_card
  card.rule_card(:csv_structure) || Card.fetch(row_card_names.first)
end

#default_item_viewObject



15
16
17
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 15

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

#default_nest_viewObject



11
12
13
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 11

def default_nest_view
  :core
end

#name_with_field_rowsObject



50
51
52
53
54
55
56
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 50

def name_with_field_rows
  return [] unless row_card_names.present?

  row_card_names.map do |item_name|
    CSV.generate_line row_from_field_names(item_name, columns)
  end.join
end

#name_with_fields_rowObject



44
45
46
47
48
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 44

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

#row_card_namesObject



58
59
60
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 58

def row_card_names
  @row_cards ||= card.item_names
end

#row_from_field_names(parent_name, field_names, view = :core) ⇒ Object



70
71
72
73
74
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 70

def row_from_field_names parent_name, field_names, view=:core
  field_names.each_with_object([parent_name]) do |field, row|
    row << nest([parent_name, field], view: view)
  end
end

#title_row(extra_titles = nil) ⇒ Object



76
77
78
79
80
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 76

def title_row extra_titles=nil
  titles = column_titles extra_titles
  return "" unless titles.present?
  CSV.generate_line titles.map(&:upcase)
end

#view: coreObject



19
20
21
22
23
24
25
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 19

view :core do
  if (item_view_options[:view] == :name_with_fields) && focal?
    title_row("item name") + name_with_field_rows
  else
    super()
  end
end

#view: csv_rowObject



27
28
29
30
31
32
33
34
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 27

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: name_with_fieldsObject



40
41
42
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 40

view :name_with_fields do
  CSV.generate_line name_with_fields_row
end

#view: unknownObject



36
37
38
# File 'card/tmpsets/set/mod008-card-mod-format/all/csv.rb', line 36

view :unknown do
  ""
end