Class: Stockr::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/stockr/export.rb

Class Method Summary collapse

Class Method Details

.allObject



12
13
14
# File 'lib/stockr/export.rb', line 12

def all
  @all ||= Part.search("") || []
end

.csvObject



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

.filenameObject



36
37
38
# File 'lib/stockr/export.rb', line 36

def filename
  "my_stockr_" + timestamp
end

.formatObject



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

  #{timestamp}

-------------------------------------------

#{Part.list.join("\n")}

-------------------------------------------
Total: #{all.size}

TXT
end

.htmlObject



53
54
# File 'lib/stockr/export.rb', line 53

def html
end

.pdfObject



56
57
# File 'lib/stockr/export.rb', line 56

def pdf
end

.timestampObject



16
17
18
# File 'lib/stockr/export.rb', line 16

def timestamp
  @ts ||= Time.now.strftime("%y-%m-%d-%H-%M-%S")
end

.txtObject



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

.xmlObject



59
60
# File 'lib/stockr/export.rb', line 59

def xml
end