class Bibox::Models::Base

Public Class Methods

new(hash) click to toggle source
# File lib/bibox/models/base.rb, line 5
def initialize(hash)
  self.class::MAPPING.keys.each { |key| self.class.send(:attr_accessor, key) }
  
  hash.each do |key, value|
    key             =     key.underscore.to_sym
    type            =     self.class::MAPPING.fetch(key, nil)
    value           =     value && type ? ::Bibox::Utilities::convert_value(value, type, use_ms_for_time: true) : value
    self.send("#{key}=", value) if self.respond_to?(key)
  end
end
parse(data) click to toggle source
# File lib/bibox/models/base.rb, line 20
def self.parse(data)
  data&.collect { |item| self.new(item) }
end

Public Instance Methods

attributes() click to toggle source
# File lib/bibox/models/base.rb, line 16
def attributes
  Hash[instance_variables.map { |name| [name.to_s.gsub(/^@/, "").to_sym, instance_variable_get(name)] }]
end