Module: YardGhurt::Util

Extended by:
ClassMethods
Included in:
YardGhurt
Defined in:
lib/yard_ghurt/util.rb

Overview

Utility methods in a separate module/mixin, so that a programmer can require/load a sole task:

require 'yard_ghurt/gfm_fix_task'

Else, programmers would be required to always require/load the entire yard_ghurt module:

require 'yard_ghurt'

All internal code should use this module.

External code can either use this module or YardGhurt, which includes this module as a mixin.

Since:

  • 1.0.0

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

TRUE_BOOLS =

Returns the lower-case Strings that will equal to true.

Returns:

  • (Array<String>)

    the lower-case Strings that will equal to true

Since:

  • 1.0.0

%w[1 on t true y yes].freeze
SEM_VER_REGEX =

Returns a very flexible (non-strict) Semantic Versioning regex, ignoring pre-release/build-metadata.

Returns:

  • a very flexible (non-strict) Semantic Versioning regex, ignoring pre-release/build-metadata

Since:

  • 1.2.1

/(?<major>\d+)(?:\.(?<minor>\d+))?(?:\.(?<patch>\d+))?/.freeze

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

If include Util is called, extend ClassMethods.

Parameters:

  • mod (Module)

    the module to extend

Since:

  • 1.0.0



36
37
38
# File 'lib/yard_ghurt/util.rb', line 36

def self.included(mod)
  mod.extend ClassMethods
end

.parse_sem_ver(str) ⇒ Hash Originally defined in module ClassMethods

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.

Parameters:

  • str (String, Object)

    the object to parse; to_s() will be called on it

Returns:

  • (Hash)

    the Semantic Version parts: {:major, :minor, :patch} defaults all values to 0 if the version cannot be parsed

See Also:

Since:

  • 1.2.1

.rm_exist(filename, output = true) ⇒ Object Originally defined in module ClassMethods

If filename exists, delete it, and if output is true, log it to stdout.

Parameters:

  • filename (String)

    the file to remove

  • output (true, false) (defaults to: true)

    whether to log it to stdout

Since:

  • 1.0.0

.to_bool(str) ⇒ true, false Originally defined in module ClassMethods

Convert str to true or false.

Even if str is not a String, to_s() will be called, so should be safe.

Parameters:

  • str (String, Object)

    the String (or Object) to convert

Returns:

  • (true, false)

    the boolean value of str

See Also:

Since:

  • 1.0.0

.yard_sem_verHash Originally defined in module ClassMethods

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.

Returns:

  • (Hash)

    YARD’s version parts

See Also:

Since:

  • 1.2.1