class Converter
Convert data to required type
Public Class Methods
error(value)
click to toggle source
# File lib/undecided/converter.rb, line 38 def self.error(value) raise Undecided::DeciderError, "#{value} Is not a correct value, " \ 'insert (1 or 0) or (true or false)' end
hash_values_to_bool(values)
click to toggle source
Convert every value from hash to a boolean value
# File lib/undecided/converter.rb, line 21 def self.hash_values_to_bool(values) raise 'Only hash values' unless values.is_a? Hash values.map { |k, v| [k, to_bool(v)] }.to_h end
process_values(values)
click to toggle source
# File lib/undecided/converter.rb, line 3 def self.process_values(values) values = to_symbol(values) hash_values_to_bool(values) end
replacing_variables(rule, values)
click to toggle source
Replaces variables from rules with values
# File lib/undecided/converter.rb, line 44 def self.replacing_variables(rule, values) process_values(values).each do |k, v| rule.gsub! k.to_s, v.to_s end rule end
to_bool(value)
click to toggle source
Transform value to boolean
# File lib/undecided/converter.rb, line 27 def self.to_bool(value) # if boolean return value return value if Undecided::Evaluator.bool?(value) # transform integer value to boolean error(value) unless [0, 1].include? value !value.to_i.zero? rescue => e puts e.message error value end
to_symbol(value)
click to toggle source
Convert array, hash's keys or solo values to symbol
# File lib/undecided/converter.rb, line 9 def self.to_symbol(value) if value.is_a?(Array) value.map(&:to_sym) elsif value.is_a? Hash value.map { |k, v| [k.to_sym, v] }.to_h else # for String and Number solo values value.to_s.to_sym end end