Class: Botz::Shell
- Inherits:
-
Object
- Object
- Botz::Shell
- Includes:
- ActiveModel::Attributes, ActiveModel::Model
- Defined in:
- lib/botz/shell.rb
Overview
botz shell access interface
Instance Method Summary collapse
- #function ⇒ Object
-
#scraper(name) ⇒ Object
rubocop:disable Lint/AssignmentInCondition, Style/RescueStandardError.
-
#spider(name) ⇒ Object
rubocop:enable Lint/AssignmentInCondition, Style/RescueStandardError.
Instance Method Details
#function ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/botz/shell.rb', line 40 def function print <<~SHELL function spider() { botz #{filepath} spider $1 } function scraper() { botz #{filepath} scraper $1 } SHELL end |
#scraper(name) ⇒ Object
rubocop:disable Lint/AssignmentInCondition, Style/RescueStandardError
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/botz/shell.rb', line 15 def scraper(name) command = scrapers[name.to_sym] while line = STDIN.gets url = line.strip begin command.call(url) rescue STDERR.puts "ERROR #{command} #{url}" end end end |
#spider(name) ⇒ Object
rubocop:enable Lint/AssignmentInCondition, Style/RescueStandardError
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/botz/shell.rb', line 28 def spider(name) command = spiders[name.to_sym] if File.pipe?(STDIN) STDIN.each_line do |line| start_url = line.strip command.call(start_url) { |url| puts url } end else command.call { |url| puts url } end end |