module Stockr
Constants
- DOTFILE
- FORMATS
- TECHUB
Public Class Methods
get_user()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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