class RegApi2::Entity::EntityBase

Base entity class.

Constants

SKIPPED_MEMBERS

Skipped property names.

Public Class Methods

new(opts = {}) click to toggle source

Initializes the instance. opts values are assigned to properties if exist. @param [Hash] opts

# File lib/reg_api2/entity/entity_base.rb, line 48
def initialize opts = {}
  methods = self.class.public_instance_methods(false).map(&:to_s)
  opts.keys.each do |key|
    next  unless methods.detect { |m| m == "#{key}=" }
    send("#{key}=", opts[key])
  end
end

Public Instance Methods

property_names() click to toggle source

Gets instance property names @return [Array(String)]

# File lib/reg_api2/entity/entity_base.rb, line 16
def property_names
  methods = self.class.public_instance_methods(false).map(&:to_s)
  methods.select do |n|
    true &&
    !SKIPPED_MEMBERS.detect { |n3| n3 == n } &&
    n =~ /^[^=\?!]+$/ &&
    methods.detect { |n2| "#{n}=" == n2 } &&
    true
  end
end
to_hash() click to toggle source

All r/w properties interpreted as symbol hash. @return [Hash] properties as hash.

# File lib/reg_api2/entity/entity_base.rb, line 29
def to_hash
  h = {}
  property_names.each do |n|
    v = self.send n.to_sym
    h[n.to_sym] = v  unless v.nil?
  end
  h
end
to_json() click to toggle source

Returns JSON @return [String] JSON @see to_hash

# File lib/reg_api2/entity/entity_base.rb, line 41
def to_json
  Yajl::Encoder.encode to_hash
end