module BooleanHelpers
Collection of methods for converting to
google's boolean integers from ruby's booleans
Public Instance Methods
boolean_field?(key)
click to toggle source
Is this key one of the boolean fields @param key [Symbol] field key @return [Boolean]
# File lib/staccato/boolean_helpers.rb, line 21 def boolean_field?(key) boolean_fields.include?(key) end
convert_boolean((k,v), hash)
click to toggle source
Method to convert a single field from bool to int @param hash [#[]=] the collector object
# File lib/staccato/boolean_helpers.rb, line 14 def convert_boolean((k,v), hash) hash[k] = boolean_field?(k) ? integer_for(v) : v end
convert_booleans(hash)
click to toggle source
Convert each boolean in the hash to integer
if it is a boolean field
@param hash [Hash] @return [Hash]
# File lib/staccato/boolean_helpers.rb, line 8 def convert_booleans(hash) hash.each_pair.with_object({}, &method(:convert_boolean)) end
integer_for(value)
click to toggle source
Convert a value to appropriate int @param value [nil, true, false, Integer] @return [nil, Integer]
# File lib/staccato/boolean_helpers.rb, line 28 def integer_for(value) case value when Integer value when TrueClass 1 when FalseClass 0 when NilClass nil end end