Module: Stockr

Defined in:
lib/stockr/export.rb,
lib/stockr.rb,
lib/stockr/part.rb,
lib/stockr/store.rb

Overview

Export Redis DB to various formats

Defined Under Namespace

Classes: Export, Part, Store

Constant Summary collapse

FORMATS =
%w{ txt csv html pdf xml }

Class Method Summary collapse

Class Method Details



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

def self.print_parts(res)
  return "Not found... go shop!" unless res && !res.empty?
  res.map(&:facts).join("\n")

end

.work(txt) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/stockr.rb', line 19

def self.work(txt)
  txt = txt.split(" ") unless txt.is_a? Array
  parse = txt
  case parse.join
  when "all" then puts Export.format
  when "web" then
    puts "Starting websever on port."
    require "stockr/web"
  when "shop" then print_parts(Part.missing)
  else
    if parse.size == 1
      if parse.join =~ /#{FORMATS.join('|')}/
        f = Export.send(parse[0].to_sym)
        "File saved! #{f}"
      else
        puts "Searching...#{txt.join}"
        print_parts Part.search(txt.join.upcase)
      end
    else
      if part = Part.create_or_increment(*parse)
        return "Done. #{part.facts}"
      else
        "Problems creating part..."
      end
    end

  end

end