Module: Licensee::HashHelper
- Included in:
- License, LicenseMeta, LicenseRules, Matchers::Matcher, ProjectFiles::ProjectFile, Projects::Project, Rule
- Defined in:
- lib/licensee/hash_helper.rb
Overview
Mixin that provides a ‘to_h` based on a class’s ‘HASH_METHODS`.
Instance Method Summary collapse
Instance Method Details
#serialize_hash_value(value) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/licensee/hash_helper.rb', line 17 def serialize_hash_value(value) return value.map { |v| v.respond_to?(:to_h) ? v.to_h : v } if value.is_a?(Array) return value.to_h if value.respond_to?(:to_h) && !value.nil? value end |
#to_h ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/licensee/hash_helper.rb', line 6 def to_h hash = {} self.class::HASH_METHODS.each do |method| key = method.to_s.delete('?').to_sym value = public_send(method) hash[key] = serialize_hash_value(value) end hash end |