Class: Stockr::Export
- Inherits:
-
Object
- Object
- Stockr::Export
- Defined in:
- lib/stockr/export.rb
Class Method Summary collapse
- .all ⇒ Object
- .csv ⇒ Object
- .filename ⇒ Object
- .format ⇒ Object
- .html ⇒ Object
- .pdf ⇒ Object
- .timestamp ⇒ Object
- .txt ⇒ Object
- .write(txt, ext) ⇒ Object
- .xml ⇒ Object
Class Method Details
.all ⇒ Object
12 13 14 |
# File 'lib/stockr/export.rb', line 12 def all @all ||= Part.search("") || [] end |
.csv ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/stockr/export.rb', line 44 def csv output = "name,qty,price\n" for p in all output << [p.name, p.qty, p.price].join(",") end output << "\n" write(output, "csv") end |
.filename ⇒ Object
36 37 38 |
# File 'lib/stockr/export.rb', line 36 def filename "my_stockr_" + end |
.format ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/stockr/export.rb', line 20 def format <<TXT Stockr Export #{} ------------------------------------------- #{Part.list.join("\n")} ------------------------------------------- Total: #{all.size} TXT end |
.html ⇒ Object
53 54 |
# File 'lib/stockr/export.rb', line 53 def html end |
.pdf ⇒ Object
56 57 |
# File 'lib/stockr/export.rb', line 56 def pdf end |
.timestamp ⇒ Object
16 17 18 |
# File 'lib/stockr/export.rb', line 16 def @ts ||= Time.now.strftime("%y-%m-%d-%H-%M-%S") end |
.txt ⇒ Object
40 41 42 |
# File 'lib/stockr/export.rb', line 40 def txt write(format, "txt") end |
.write(txt, ext) ⇒ Object
62 63 64 65 66 |
# File 'lib/stockr/export.rb', line 62 def write(txt, ext) fname = filename + ".#{ext}" File.open(fname, "w") { |f| f << txt } fname end |
.xml ⇒ Object
59 60 |
# File 'lib/stockr/export.rb', line 59 def xml end |