Top Level Namespace
- Extended by:
- Cem
Defined Under Namespace
Modules: CLog, Cem Classes: Array, Dir2D, File, Grid, Numeric, Point2D, Point3D, Seg2D
Constant Summary collapse
- Dirs2D =
[Point2D.new(0, -1), Point2D.new(1, 0), Point2D.new(0, 1), Point2D.new(-1, 0)]
Constants included from Cem
Instance Method Summary collapse
-
#crequire(requireName, gem_name = nil) ⇒ Object
Require the given ruby file and if loading fails, try to install the gem of the same name or given parameter.
- #isHTML5Element(element) ⇒ Object
-
#wsl? ⇒ Boolean
Returns true if this script is running on the Windows Sub-System for Linux, i.e.
-
#wslpath(path, mode = "") ⇒ Object
If on wsl? then the given is converted from a Windows path to a Linux path (e.g. “C:" becomes ”/mnt/c/“).
Methods included from Cem
Instance Method Details
#crequire(requireName, gem_name = nil) ⇒ Object
Require the given ruby file and if loading fails, try to install the gem of the same name or given parameter
5 6 7 8 9 10 11 12 |
# File 'lib/cem/ccommon.rb', line 5 def crequire(requireName, gem_name = nil) require requireName rescue LoadError gem_name = requireName if gem_name.nil? system("gem install #{gem_name}") Gem.clear_paths require requireName end |
#isHTML5Element(element) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/cem/ccommon.rb', line 72 def isHTML5Element(element) # https://html.spec.whatwg.org/#elements-3 @valid_elements ||= %w(a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins kbd label legend li link main map mark math menu meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp script section select slot small source span strong style sub summary sup svg table tbody td template textarea tfoot th thead time title tr track u ul var video wbr) return @valid_elements.include?(element.to_s.downcase) end |
#wsl? ⇒ Boolean
Returns true if this script is running on the Windows Sub-System for Linux, i.e. under Linux where the host is Windows.
If true, interoperability with Windows is possible.
51 52 53 |
# File 'lib/cem/ccommon.rb', line 51 def wsl? @@wsl ||= File.file?('/proc/version') && File.open('/proc/version', &:gets).downcase.include?("microsoft") end |
#wslpath(path, mode = "") ⇒ Object
If on wsl? then the given is converted from a Windows path to a Linux path (e.g. “C:" becomes ”/mnt/c/“)
Uses the wslpath command, passes mode to wslpath:
-a force result to absolute path format
-u translate from a Windows path to a WSL path (default)
-w translate from a WSL path to a Windows path
-m translate from a WSL path to a Windows path, with '/' instead of '\'
66 67 68 69 70 |
# File 'lib/cem/ccommon.rb', line 66 def wslpath(path, mode = "") return path if !wsl? return `wslpath #{mode} '#{path}'`.strip end |