class Minfraud::Components::Base
This is a parent class for all components. It defines a method which is used for basic JSON representation of the component objects.
Constants
- BOOLS
Keys that have to remain boolean
Public Instance Methods
to_json(*_args)
click to toggle source
A JSON representation of component attributes.
@return [Hash]
# File lib/minfraud/components/base.rb, line 11 def to_json(*_args) instance_variables.reduce({}) { |mem, e| populate!(mem, e) } end
Private Instance Methods
populate!(hash, v_sym)
click to toggle source
Create a hash containing a JSON representation of instance variable name and its value.
@param hash [Hash] An accumulator.
@param v_sym [Symbol] An instance variable symbol.
@return [Hash]
# File lib/minfraud/components/base.rb, line 25 def populate!(hash, v_sym) return hash unless (value = instance_variable_get(v_sym)) key = v_sym.to_s.gsub(/@/, '') hash.merge!(key => represent(key, value)) end
represent(key, value)
click to toggle source
Return the value according to the request format.
@param key [Symbol] An instance variable symbol.
@param value [Object] An instance variable value.
@return [Object]
# File lib/minfraud/components/base.rb, line 39 def represent(key, value) BOOLS.include?(key) ? value : value.to_s end