Class: Formotion::Base

Inherits:
Object show all
Defined in:
lib/formotion/base.rb

Direct Known Subclasses

Form, Row, Section

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
# File 'lib/formotion/base.rb', line 5

def initialize(params = {})
  params.each { |key, value|
    if  self.class.const_get(:PROPERTIES).member? key.to_sym
      self.send("#{key}=".to_sym, value)
    end
  }
end

Instance Method Details

#copyWithZone(zone) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/formotion/base.rb', line 53

def copyWithZone(zone)
  copy = self.class.allocWithZone(zone).init
  self.class.const_get(:SERIALIZE_PROPERTIES).each {|prop|
    copy.send("#{prop}=".to_sym, self.send(prop))
  }
  copy
end

#encodeWithCoder(encoder) ⇒ Object

NSCoding + NSCopying



38
39
40
41
42
# File 'lib/formotion/base.rb', line 38

def encodeWithCoder(encoder)
  self.class.const_get(:SERIALIZE_PROPERTIES).each {|prop|
    encoder.encodeObject(self.send(prop), forKey: prop.to_s)
  }
end

#hashObject

Needed so things like @targets with KVO

(storing Row instances as keys of a hash)


25
26
27
# File 'lib/formotion/base.rb', line 25

def hash
  "#{self.class.name}-id-#{object_id}".hash
end

#initWithCoder(decoder) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/formotion/base.rb', line 44

def initWithCoder(decoder)
  self.init
  self.class.const_get(:SERIALIZE_PROPERTIES).each {|prop|
    value = decoder.decodeObjectForKey(prop.to_s)
    self.send("#{prop}=".to_sym, value) if not value.nil?
  }
  self
end

#isEqual(other) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/formotion/base.rb', line 29

def isEqual(other)
  return true if other == self
  return false unless other # if other is nil
  return false unless other.class == self.class

  return other.object_id == self.object_id
end

#to_hashObject



13
14
15
16
17
18
19
20
# File 'lib/formotion/base.rb', line 13

def to_hash
  h = {}
   self.class.const_get(:PROPERTIES).each { |prop|
    val = self.send(prop)
    h[prop] = val if val
  }
  h
end