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
stras a non-strict Semantic Version: d+.d+.d+. -
#rm_exist(filename, output = true) ⇒ Object
If
filenameexists, delete it, and ifoutputistrue, log it to stdout. -
#to_bool(str) ⇒ true, false
Convert
strtotrueorfalse. -
#yard_sem_ver ⇒ Hash
Returns YARD’s version as a
Hashof 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.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/yard_ghurt/util.rb', line 82 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.
47 48 49 50 51 52 |
# File 'lib/yard_ghurt/util.rb', line 47 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.
64 65 66 |
# File 'lib/yard_ghurt/util.rb', line 64 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.
110 111 112 113 114 115 116 117 118 |
# File 'lib/yard_ghurt/util.rb', line 110 def yard_sem_ver return @yard_sem_ver unless @yard_sem_ver.nil? require 'yard' @yard_sem_ver = parse_sem_ver(defined?(YARD::VERSION) ? YARD::VERSION : '') return @yard_sem_ver end |