Class: TFSGraph::Entity
- Inherits:
-
Object
show all
- Defined in:
- lib/tfs_graph/entity.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ Entity
Returns a new instance of Entity.
9
10
11
12
13
14
15
16
17
|
# 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
|
Class Method Details
.inherited(klass) ⇒ Object
3
4
5
6
7
|
# 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
|
Instance Method Details
#schema ⇒ Object
34
35
36
|
# File 'lib/tfs_graph/entity.rb', line 34
def schema
self.class::SCHEMA
end
|
#to_hash ⇒ Object
Also known as:
attributes
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# 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
|