Module: YardGhurt::Util::ClassMethods
- Included in:
- YardGhurt::Util
- Defined in:
- lib/yard_ghurt/util.rb
Overview
Instance Method Summary collapse
-
#parse_sem_ver(str) ⇒ Hash
Parse
str
as a non-strict Semantic Version: d+.d+.d+. -
#rm_exist(filename, output = true) ⇒ Object
If
filename
exists, delete it, and ifoutput
istrue
, log it to stdout. -
#to_bool(str) ⇒ true, false
Convert
str
totrue
orfalse
. -
#yard_sem_ver ⇒ Hash
Returns YARD's version as a
Hash
of parts: { major: 0, minor: 0, patch: 0 }.
Instance Method Details
#parse_sem_ver(str) ⇒ Hash
Parse str
as a non-strict Semantic Version:
\d+.\d+.\d+
Unlike the specification, minor and patch are optional. Also, pre-release and build metadata are ignored. This is used for checking the YARD version internally, so needs to be very flexible.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/yard_ghurt/util.rb', line 86 def parse_sem_ver(str) sem_ver = { major: 0,minor: 0,patch: 0, } match = SEM_VER_REGEX.match(str.to_s.gsub(/\s+/u,'')) return sem_ver unless match sem_ver[:major] = match[:major].to_i sem_ver[:minor] = match[:minor].to_i unless match[:minor].nil? sem_ver[:patch] = match[:patch].to_i unless match[:patch].nil? return sem_ver end |
#rm_exist(filename, output = true) ⇒ Object
If filename
exists, delete it, and if output
is true
, log it to stdout.
51 52 53 54 55 56 |
# File 'lib/yard_ghurt/util.rb', line 51 def rm_exist(filename,output=true) return unless File.exist?(filename) puts "[#{filename}]: - Deleted" if output File.delete(filename) end |
#to_bool(str) ⇒ true, false
Convert str
to true
or false
.
Even if str
is not a String, to_s() will be called, so should be safe.
68 69 70 |
# File 'lib/yard_ghurt/util.rb', line 68 def to_bool(str) return TRUE_BOOLS.include?(str.to_s.downcase) end |
#yard_sem_ver ⇒ Hash
Returns YARD's version as a Hash
of parts:
{ major: 0, minor: 0, patch: 0 }
If the version can not be parsed, it will return the exact same Hash
as above with all values to 0
.
On initial call, it will parse it and store it. On subsequent calls, it will return the stored value.
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/yard_ghurt/util.rb', line 114 def yard_sem_ver return @yard_sem_ver unless @yard_sem_ver.nil? require 'yard' if defined?(YARD::VERSION) ver = YARD::VERSION else ver = '' end return(@yard_sem_ver = parse_sem_ver(ver)) end |