class Quovo::Models::Base

Public Class Methods

fields(fields = nil) click to toggle source
# File lib/quovo/models/base.rb, line 6
def self.fields(fields = nil)
  if fields
    @fields = fields.map(&:to_sym)
    @fields.each do |field|
      attr_reader field
    end
  else
    @fields || []
  end
end
new(props) click to toggle source
# File lib/quovo/models/base.rb, line 17
def initialize(props)
  props.each do |field, value|
    instance_variable_set("@#{field}", value)
  end
end

Public Instance Methods

[](field) click to toggle source
# File lib/quovo/models/base.rb, line 23
def [](field)
  send(field)
end
to_h() click to toggle source
# File lib/quovo/models/base.rb, line 33
def to_h
  to_hash
end
to_hash() click to toggle source
# File lib/quovo/models/base.rb, line 27
def to_hash
  self.class.fields.map do |field|
    [field, self[field]]
  end.to_h
end