module Spark::Helpers
Public Instance Methods
dasherize(input)
click to toggle source
# File lib/fleetio_spark/helper.rb, line 63 def dasherize(input) input.strip.gsub(/[\W,_]+/, '-') end
dasherize_keys(obj)
click to toggle source
# File lib/fleetio_spark/helper.rb, line 59 def dasherize_keys(obj) obj.deep_transform_keys{ |key| dasherize(key.to_s) } end
set_aria_keys( options, tl_keys=[] )
click to toggle source
Convert aria: { key: val } to 'aria-key' => val
# File lib/fleetio_spark/helper.rb, line 16 def set_aria_keys( options, tl_keys=[] ) # Add 'aria' parent to passed top level keys tl_keys = tl_keys.split(' ') if tl_keys.is_a? String tl_keys = tl_keys | DEFAULT_ARIA_KEYS options = sub_key options, tl_keys, 'aria' opts = {} options['aria'].each do |key, val| opts["aria-#{key}"] = val end options.delete 'aria' options.merge! opts options end
set_data_keys( options={}, tl_keys=[] )
click to toggle source
Move top level keys under data:
# File lib/fleetio_spark/helper.rb, line 9 def set_data_keys( options={}, tl_keys=[] ) tl_keys = tl_keys.split(' ') if tl_keys.is_a? String tl_keys = tl_keys | DEFAULT_DATA_KEYS sub_key options, tl_keys, 'data' end
set_type_defaults( type, options={} )
click to toggle source
# File lib/fleetio_spark/helper.rb, line 55 def set_type_defaults( type, options={} ) ( INPUT_OPTIONS[type] || {} ).deep_merge options end
sub_key(options, tl_keys, parent)
click to toggle source
Move top level keys under new parent key
# File lib/fleetio_spark/helper.rb, line 36 def sub_key(options, tl_keys, parent) options = dasherize_keys( options ) tl_keys = tl_keys.split(' ') if tl_keys.is_a? String parent = parent.to_s if parent.is_a?( Symbol ) options[parent] ||= {} new_hash = {} # Look through option keys and reparent keys which match dasherized search keys options.each do |k,v| new_hash[dasherize k] = options.delete k if tl_keys.include? dasherize k end options[parent].merge! new_hash options end