Module: Booker::Browser

Included in:
CLI
Defined in:
lib/booker/config.rb

Overview

return browser (chrome) opening command

Constant Summary collapse

SCHEME =

what an explicit scheme looks like. #domain and #prep are two halves of one grammar - is this a url, does it already say how to fetch it - so both read the rule from here rather than spelling it out twice and drifting

/[a-z][a-z0-9+.-]*:\/\//i

Instance Method Summary collapse

Instance Method Details

#browseObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/booker/config.rb', line 24

def browse
  if OS.windows?
    # alternatively, start seems to work - probably check if powershell v cygwin?
    '/cygdrive/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe '
  elsif OS.mac?
    "open "
  else
    # linux? is defined as "neither of the above", so there is no fourth
    # branch for #browse to fall out of and return nil from
    "xdg-open "
  end
end

#domainObject

does this argument look like a website rather than a search term? an explicit scheme, or a bare host with a dot and an alphabetic tld. every tld has to work: completion inserts real bookmark urls, and the old (io|com|net|org|...) list sent .dev and .ai off to the search engine



46
47
48
# File 'lib/booker/config.rb', line 46

def domain
  %r{\A(?:#{SCHEME}\S+|(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}(?::\d+)?(?:[/?#]\S*)?)\z}io
end

#prep(url) ⇒ Object

only a bare host needs a scheme invented for it. testing for "http" alone sent everything else down the same branch, so a completed chrome://bookmarks/ came out as http://chrome://bookmarks/



53
54
55
# File 'lib/booker/config.rb', line 53

def prep(url)
  /\A#{SCHEME}/io.match?(url) ? url : "http://" + url
end