Module: Card::Set::All::AllCsv::CsvFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod006-basic_formats/all/all_csv.rb

Instance Method Summary collapse

Instance Method Details

#column_title(opts) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 95

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



86
87
88
89
90
91
92
93
# File 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 86

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
65
66
67
68
# File 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 62

def columns
  columns = []
  csv_structure_card.format.each_nested_field do |chunk|
    columns << chunk.referee_name.tag
  end
  columns
end

#csv_structure_cardObject



70
71
72
# File 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 70

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

#default_item_viewObject



15
16
17
# File 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 15

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

#default_nest_viewObject



11
12
13
# File 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 11

def default_nest_view
  :core
end

#name_with_field_rowsObject



50
51
52
53
54
55
56
# File 'tmpsets/set/mod006-basic_formats/all/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 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 44

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

#row_card_namesObject



58
59
60
# File 'tmpsets/set/mod006-basic_formats/all/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



74
75
76
77
78
# File 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 74

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



80
81
82
83
84
# File 'tmpsets/set/mod006-basic_formats/all/all_csv.rb', line 80

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