Class: Notes::HtmlExport

Inherits:
BaseExport show all
Defined in:
lib/notes/export/html_export.rb

Constant Summary collapse

DOCTYPE =
'<!DOCTYPE html>'
HTML =
'<html>'
HEAD =
'<head>'
BODY =
'<body>'
ENCODING =
'<meta http-equiv="content-type" content="text/html; charset=utf-8" />'
TITLE =
'<title>Notes</title>'
TABLE =
'<table style="text-align: center;">'
TABLE_ROW =
'<tr>'
TABLE_CELL =
'<td>'

Constants inherited from BaseExport

BaseExport::DESCRIPTION, BaseExport::DUE_DATE, BaseExport::TAG, BaseExport::TOKEN

Instance Method Summary collapse

Constructor Details

#initialize(output_file_path) ⇒ HtmlExport

Returns a new instance of HtmlExport.



13
14
15
# File 'lib/notes/export/html_export.rb', line 13

def initialize output_file_path
  @file = File.new output_file_path , 'w+'
end

Instance Method Details

#export_note(note_hash) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/notes/export/html_export.rb', line 29

def export_note note_hash
  res = TABLE_ROW
  res += TABLE_CELL + note_hash[Notes::Options::TOKEN.to_s] + get_closing_tag(TABLE_CELL)
  res += TABLE_CELL + get_tags_string(note_hash[Notes::Options::TAG.to_s]) + get_closing_tag(TABLE_CELL)
  res += TABLE_CELL + note_hash[Notes::Options::DESCRIPTION.to_s] + get_closing_tag(TABLE_CELL)
  res += TABLE_CELL + note_hash[Notes::Options::DUE_DATE.to_s] + get_closing_tag(TABLE_CELL)
  res += get_closing_tag(TABLE_ROW)
  res
end

#export_notes(notes_list) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/notes/export/html_export.rb', line 17

def export_notes notes_list
  res = TABLE + TABLE_ROW  + TABLE_CELL + TOKEN + get_closing_tag(TABLE_CELL) + TABLE_CELL + TAG + get_closing_tag(TABLE_CELL)
  res += TABLE_CELL + DESCRIPTION + get_closing_tag(TABLE_CELL) + TABLE_CELL + DUE_DATE + get_closing_tag(TABLE_CELL)
  res += get_closing_tag(TABLE_ROW)
  notes_list.each do |note|
    res += export_note note
  end
  res += get_closing_tag TABLE
  @file.puts(attach_headers res)
  @file.close
end