module Charging::Helpers

Public Instance Methods

extract_uuid(uri) click to toggle source
# File lib/charging/helpers.rb, line 31
def extract_uuid(uri)
  uri.split("/").last
rescue
  ""
end
hashify(object, attributes) click to toggle source
# File lib/charging/helpers.rb, line 24
def hashify(object, attributes)
  attributes.inject({}) do |result, attribute|
    result[attribute] = object.send(attribute)
    result
  end
end
load_variables(object, attributes, hash) click to toggle source
# File lib/charging/helpers.rb, line 7
def load_variables(object, attributes, hash)
  attributes.each do |attribute|
    value = hash.fetch(attribute, hash.fetch(attribute.to_s, nil))
    object.instance_variable_set "@#{attribute}", value
  end
end
required_arguments!(arguments) click to toggle source
# File lib/charging/helpers.rb, line 14
def required_arguments!(arguments)
  errors = []

  arguments.each do |key, value|
    errors << "#{key} required" if value.nil?
  end

  raise ArgumentError, errors.join(', ') if errors.any?
end