class TFSGraph::Entity

Public Class Methods

inherited(klass) click to toggle source
# File lib/tfs_graph/entity.rb, line 3
def self.inherited(klass)
  define_singleton_method :act_as_entity do
    attr_accessor *klass::SCHEMA.keys
  end
end
new(args) click to toggle source
# File lib/tfs_graph/entity.rb, line 9
def initialize(args)
  schema.each do |key, details|
    value = (args[key] || details[:default])

    value = ressurect_time(value) if details[:type] == Time

    send "#{key}=", value
  end
end

Public Instance Methods

attributes()
Alias for: to_hash
schema() click to toggle source
# File lib/tfs_graph/entity.rb, line 34
def schema
  self.class::SCHEMA
end
to_hash() click to toggle source
# File lib/tfs_graph/entity.rb, line 19
def to_hash
  hash = {}
  schema.keys.each do |key|
    hash[key] = send key
  end

  hash.each do |k,v|
    next unless v.is_a? Time
    hash[k] = v.utc.to_i
  end

  hash
end
Also aliased as: attributes

Private Instance Methods

ressurect_time(time) click to toggle source
# File lib/tfs_graph/entity.rb, line 39
def ressurect_time(time)
  return time if (time.is_a?(Time) || time.nil?)
  Time::at time.to_i
end