lib/how_is/frontmatter.rb in how_is-24.0.0 vs lib/how_is/frontmatter.rb in how_is-25.0.0

- old
+ new

@@ -1,16 +1,26 @@ # frozen_string_literal: true require "how_is/version" +require "okay/warning_helpers" module HowIs + ## + # Module for generating YAML frontmatter, as used by Jekyll and other + # blog engines. module Frontmatter + extend Okay::WarningHelpers + # Generates YAML frontmatter, as is used in Jekyll and other blog engines. # # E.g., # generate_frontmatter({'foo' => "bar %{baz}"}, {'baz' => "asdf"}) # => "---\nfoo: bar asdf\n" + # + # @param frontmatter [Hash] Frontmatter for the report. + # @param report_data [Hash] The report data itself. + # @return [String] A YAML dump of the generated frontmatter. def self.generate(frontmatter, report_data) return "" if frontmatter.nil? frontmatter = convert_keys(frontmatter, :to_s) report_data = convert_keys(report_data, :to_sym) @@ -27,20 +37,15 @@ end # @example # convert_keys({'foo' => 'bar'}, :to_sym) # # => {:foo => 'bar'} + # @param data [Hash] The input hash. + # @param method_name [Symbol] The method name used to convert keys. + # (E.g. :to_s, :to_sym, etc.) + # @return [Hash] The converted result. def self.convert_keys(data, method_name) data.map { |k, v| [k.send(method_name), v] }.to_h end private_class_method :convert_keys - - def self.silence_warnings(&_block) - old_verbose = $VERBOSE - $VERBOSE = nil # Disable warnings entirely. - yield - ensure - $VERBOSE = old_verbose - end - private_class_method :silence_warnings end end