Class: Rebrandly::Element
- Inherits:
-
Object
- Object
- Rebrandly::Element
- Defined in:
- lib/rebrandly/element.rb
Overview
General class to map Rebrandly objects to Ruby objects
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Element
constructor
A new instance of Element.
- #to_h ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Element
Returns a new instance of Element.
4 5 6 7 |
# File 'lib/rebrandly/element.rb', line 4 def initialize(attrs={}) # Only set the attributes if the method exists, this way we can ignore deprecated attributes attrs.each { |k,v| send("#{k.underscore}=", v) if respond_to?("#{k.underscore}=") } end |
Instance Method Details
#to_h ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/rebrandly/element.rb', line 9 def to_h Hash[ *instance_variables.map do |variable| name = variable[1..-1].to_sym # Drop the @ sign at the front [name.to_sym, instance_variable_get(variable)] end.flatten ] end |