Class: Booker
Overview
get web opening command
Instance Method Summary collapse
-
#initialize(args) ⇒ Booker
constructor
A new instance of Booker.
- #parse(args) ⇒ Object
Methods included from Browser
#browse, #domain, #prep, #search, #wrap
Methods included from OS
Constructor Details
#initialize(args) ⇒ Booker
Returns a new instance of Booker.
11 12 13 |
# File 'lib/booker.rb', line 11 def initialize(args) parse args end |
Instance Method Details
#parse(args) ⇒ Object
15 16 17 18 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/booker.rb', line 15 def parse(args) if args.none? # no args given, show help puts HELP_BANNER exit 1 end # doing autocompletion if args[0] == "--complete" args.shift # remove flag allargs = args.join(' ') bm = Bookmarks.new(allargs) bm.autocomplete exit 0 end # doing forced bookmarking if args[0] == "--bookmark" or args[0] == "-b" bm = Bookmarks.new('') bookmark = bm.bookmark_id(args[1]) url = bm.bookmark_url(bookmark) puts 'opening ' + url + '...' exec browse << wrap(url) exit 0 end # doing forced searching if args[0] == "--search" or args[0] == "-s" args.shift # remove flag puts 'searching ' + allargs + '...' exec browse << search << allargs exit 0 end # interpret while args do allargs = "'" + args.join(' ') + "'" browsearg = args.shift if /[0-9]/.match(browsearg[0]) # bookmark bm = Bookmarks.new('') bookmark = bm.bookmark_id(browsearg) url = bm.bookmark_url(bookmark) puts 'opening ' + url + '...' exec browse << wrap(url) elsif domain.match(browsearg) # website puts 'opening ' + browsearg + '...' exec browse << wrap(prep(browsearg)) else # just search for these arguments puts 'searching ' + allargs + '...' exec browse << search << allargs end end end |