Module: Licensee::HashHelper

Included in:
License, LicenseMeta, LicenseRules, Matchers::Matcher, ProjectFiles::ProjectFile, Projects::Project, Rule
Defined in:
lib/licensee/hash_helper.rb

Instance Method Summary collapse

Instance Method Details

#to_hObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/licensee/hash_helper.rb', line 5

def to_h
  hash = {}
  self.class::HASH_METHODS.each do |method|
    key = method.to_s.delete('?').to_sym
    value = public_send(method)
    hash[key] = if value.is_a?(Array)
                  value.map { |v| v.respond_to?(:to_h) ? v.to_h : v }
                elsif value.respond_to?(:to_h) && !value.nil?
                  value.to_h
                else
                  value
                end
  end

  hash
end