Class: MakeExportable::HTML
- Inherits:
-
ExportableFormat
- Object
- ExportableFormat
- MakeExportable::HTML
- Defined in:
- lib/make_exportable/exportable_formats/html.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#data_headers ⇒ Object
Returns the value of attribute data_headers.
-
#data_set ⇒ Object
Returns the value of attribute data_set.
Attributes inherited from ExportableFormat
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(data_set, data_headers = []) ⇒ HTML
constructor
A new instance of HTML.
- #sanitize(value) ⇒ Object
Methods inherited from ExportableFormat
#generate_header_option, register_format
Constructor Details
#initialize(data_set, data_headers = []) ⇒ HTML
Returns a new instance of HTML.
10 11 12 13 14 15 |
# File 'lib/make_exportable/exportable_formats/html.rb', line 10 def initialize(data_set, data_headers=[]) self.long = 'HTML' self.mime_type = 'text/html; charset=utf-8;' self.data_set = data_set self.data_headers = data_headers end |
Instance Attribute Details
#data_headers ⇒ Object
Returns the value of attribute data_headers.
8 9 10 |
# File 'lib/make_exportable/exportable_formats/html.rb', line 8 def data_headers @data_headers end |
#data_set ⇒ Object
Returns the value of attribute data_set.
8 9 10 |
# File 'lib/make_exportable/exportable_formats/html.rb', line 8 def data_set @data_set end |
Instance Method Details
#generate ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/make_exportable/exportable_formats/html.rb', line 17 def generate generate_header_option(data_headers) output = "<table>\n" unless data_headers.blank? output << "\t<tr>\n" output << data_headers.map {|h| "\t\t<th>#{sanitize(h.humanize.titleize)}</th>\n" }.join output << "\t</tr>\n" end data_set.each do |row| output << "\t<tr>\n" output << row.map {|field| "\t\t<td>#{sanitize(field)}</td>\n"}.join output << "\t</tr>\n" end output << "</table>\n" return output end |
#sanitize(value) ⇒ Object
34 35 36 |
# File 'lib/make_exportable/exportable_formats/html.rb', line 34 def sanitize(value) value.gsub(/</, '<').gsub(/>/, '>') end |