Top Level Namespace
- Extended by:
- Cem
Defined Under Namespace
Modules: CLog, Cem Classes: Array, Dir2D, File, Grid, Module, Numeric, Point2D, Point3D, Point4D, Seg2D
Constant Summary collapse
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
-
#peql(actual, expected = :unknown_peql_token, msg = nil) ⇒ Object
Puts+eql? == peql Performs a equal comparison and outputs the result to console in the form.
-
#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 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cem/ccommon.rb', line 5 def crequire(requireName, gem_name = nil) if defined?(Bundler) begin require requireName # If run under bundler then crequire is not needed end else begin require requireName rescue LoadError gem_name = requireName if gem_name.nil? system("gem install #{gem_name}") Gem.clear_paths require requireName end end end |
#isHTML5Element(element) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/cem/ccommon.rb', line 127 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 |
#peql(actual, expected = :unknown_peql_token, msg = nil) ⇒ Object
Puts+eql? == peql Performs a equal comparison and outputs the result to console in the form
“#msg: Expected #expected, but got #actual”
expected may be kept empty, in which case the msg is adjusted
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cem/ccommon.rb', line 32 def peql(actual, expected=:unknown_peql_token, msg=nil) if expected == :unknown_peql_token puts "#{msg}: Didn't know what to expect and got '#{actual}'" else if actual == expected puts "#{msg}: Expected '#{expected}' and got it!" else puts "#{msg}: Expected '#{expected}', but got '#{actual}!" end end 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.
106 107 108 |
# File 'lib/cem/ccommon.rb', line 106 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 '\'
121 122 123 124 125 |
# File 'lib/cem/ccommon.rb', line 121 def wslpath(path, mode = "") return path if !wsl? return `wslpath #{mode} '#{path}'`.strip end |