Class: Relinkly::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/relinkly/element.rb

Overview

General class to map Relinkly objects to Ruby objects

Direct Known Subclasses

Creator, Domain, Integration, Link, Tag, Workspace

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Element

Returns a new instance of Element.



6
7
8
9
# File 'lib/relinkly/element.rb', line 6

def initialize(attrs = {})
  # Only set the attributes if the method exists, this way we can ignore deprecated attributes
  attrs.each { |k, v| send("#{k.relinkly_underscore}=", v) if respond_to?("#{k.relinkly_underscore}=") }
end

Instance Method Details

#to_hObject



11
12
13
14
15
16
17
18
# File 'lib/relinkly/element.rb', line 11

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