Class: SkyDB::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/skydb/property.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Property

Initializes the property.



10
11
12
13
14
15
# File 'lib/skydb/property.rb', line 10

def initialize(options={})
  self.id = options[:id].to_i
  self.name = options[:name]
  self.transient = options[:transient] || false
  self.data_type = options[:data_type] || "string"
end

Instance Attribute Details

#data_typeObject

The property’s data type.



34
35
36
# File 'lib/skydb/property.rb', line 34

def data_type
  @data_type
end

#idObject

The property identifier.



25
26
27
# File 'lib/skydb/property.rb', line 25

def id
  @id
end

#nameObject

The name of the property.



28
29
30
# File 'lib/skydb/property.rb', line 28

def name
  @name
end

#transientObject

A flag stating if the value of the property only exists for a single moment.



31
32
33
# File 'lib/skydb/property.rb', line 31

def transient
  @transient
end

Instance Method Details

#as_json(*a) ⇒ Object



67
# File 'lib/skydb/property.rb', line 67

def as_json(*a); return to_hash(*a); end

#from_hash(hash, *a) ⇒ Object

Decodes a hash into a property.



59
60
61
62
63
64
65
# File 'lib/skydb/property.rb', line 59

def from_hash(hash, *a)
  self.id = !hash.nil? ? hash['id'].to_i : 0
  self.name = !hash.nil? ? hash['name'] : ''
  self.transient = !hash.nil? ? hash['transient'] : false
  self.data_type = !hash.nil? ? hash['dataType'] : ''
  return self
end

#to_hash(*a) ⇒ Object

Encodes the property into a hash.



48
49
50
51
52
53
54
55
56
# File 'lib/skydb/property.rb', line 48

def to_hash(*a)
  hash = {
    'name' => name,
    'transient' => transient,
    'dataType' => data_type,
  }
  hash['id'] = id if id < 0 || id > 0
  return hash
end

#to_json(*a) ⇒ Object



68
# File 'lib/skydb/property.rb', line 68

def to_json(*a); return as_json(*a).to_json; end