Class: DisplayFor::Builder::Csv
Instance Attribute Summary
#collection
Attributes inherited from Base
#html_options, #namespace, #resource_class, #template
Instance Method Summary
collapse
#default_actions, #initialize
Methods inherited from Base
#action, #attribute, #html, #initialize
Instance Method Details
#build_actions(resource) ⇒ Object
13
14
15
|
# File 'lib/display_for/builder/csv.rb', line 13
def build_actions(resource)
nil
end
|
5
6
7
|
# File 'lib/display_for/builder/csv.rb', line 5
def
@attributes.map { |attribute| quote(attribute.label(@resource_class)) }.join(',').html_safe
end
|
#build_row(resource) ⇒ Object
9
10
11
|
# File 'lib/display_for/builder/csv.rb', line 9
def build_row(resource)
@attributes.map { |attribute| quote(attribute.content(resource)) }.join(',').html_safe
end
|
#quote(string) ⇒ Object
17
18
19
|
# File 'lib/display_for/builder/csv.rb', line 17
def quote(string)
"\"#{string.gsub('"', '""')}\"".html_safe
end
|
#to_s ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/display_for/builder/csv.rb', line 21
def to_s
result = []
@collection.each do |resource|
result << build_row(resource)
end
result.join("\n").html_safe
end
|