Module: Charging::Helpers
- Defined in:
- lib/charging/helpers.rb
Class Method Summary collapse
- .extract_uuid(uri) ⇒ Object
- .hashify(object, attributes) ⇒ Object
- .load_variables(object, attributes, hash) ⇒ Object
- .required_arguments!(arguments) ⇒ Object
Class Method Details
.extract_uuid(uri) ⇒ Object
31 32 33 34 35 |
# File 'lib/charging/helpers.rb', line 31 def extract_uuid(uri) uri.split("/").last rescue "" end |
.hashify(object, attributes) ⇒ Object
24 25 26 27 28 29 |
# 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) ⇒ Object
7 8 9 10 11 12 |
# 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) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# 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 |