Module: Stockr

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

Defined Under Namespace

Classes: Export, Import, Part, Store

Constant Summary collapse

FORMATS =
%w{ txt csv html pdf xml }
DOTFILE =
ENV['HOME'] + "/.stockr"
TECHUB =

TECHUB = “techub.heroku.com

"http://localhost:3000"

Class Method Summary collapse

Class Method Details

.get_userObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stockr.rb', line 18

def self.get_user
  unless File.exists?(DOTFILE)
    puts "What\`s your techub username?"
    name = gets.chomp
    puts "Password?"
    pass = gets.chomp
    File.open(DOTFILE, "w") { |f| f << "name: #{name}\npass: #{pass}"}
  end
  @conf = YAML.load(File.read(DOTFILE))
  [@conf["name"], @conf["pass"]]
end

.run(txt) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stockr.rb', line 30

def self.run(txt)
  if txt.size == 1
    if txt.join =~ /#{FORMATS.join('|')}/
      f = Export.send(txt[0].to_sym)
      "File saved! #{f}"
    else
      puts "Searching...#{txt.join}"
      res = Part.search(txt.join.upcase)
      puts (res && !res.empty?) ? Export.format(res) : "Not found... go shop!"
      res
    end
  else
    if part = Part.create_or_increment(*txt)
      puts "Ok, #{part.facts}"
    else
      puts "Problems creating part..."
    end
    part
  end
end

.work(txt) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/stockr.rb', line 51

def self.work(txt)
  get_user
  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 puts Export.format(Part.missing)
  when /load.*/ then Import.from_file txt[1] #ARGF
  when /pull.*/ then Import.from_web
  when /push.*/ then Export.to_web
  else run(txt)
  end

end