module Cura::Attributes::HasAttributes
Adds the `update_attributes` method.
Constants
- VALID_SIZE_SYMBOLS
Public Class Methods
included(base)
click to toggle source
# File lib/cura/attributes/has_attributes.rb, line 33 def included(base) base.extend(ClassMethods) end
new(attributes={})
click to toggle source
Initialize this object by optionally updating attributes with a Hash.
@param [#to_h] attributes Attributes
to set after initializing.
Calls superclass method
# File lib/cura/attributes/has_attributes.rb, line 41 def initialize(attributes={}) update_attributes(attributes) super end
Public Instance Methods
update_attributes(attributes={})
click to toggle source
Update any attributes on this object.
@param [#to_h] attributes @return [Hash] The attributes.
# File lib/cura/attributes/has_attributes.rb, line 51 def update_attributes(attributes={}) attributes = convert_attributes(attributes) attributes.each { |name, value| send("#{name}=", value) } end
Protected Instance Methods
convert_attributes(attributes={})
click to toggle source
Convert the attributes to a Hash and any other conversions that may need to happen.
@param [#to_h] attributes @return [Hash] The attributes.
# File lib/cura/attributes/has_attributes.rb, line 76 def convert_attributes(attributes={}) attributes.to_h end
validate_size_attribute(value)
click to toggle source
# File lib/cura/attributes/has_attributes.rb, line 61 def validate_size_attribute(value) if value.is_a?(Symbol) raise ArgumentError, "must be one of #{VALID_SIZE_SYMBOLS.join(', ')}" unless VALID_SIZE_SYMBOLS.include?(value) else value = value.to_i value = 0 if value < 0 end value end