-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
65 lines (52 loc) · 1.09 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require "ohm"
require "ohm/contrib"
class NilClass
def empty?; true; end
end
class Persona < Ohm::Model
include Ohm::Typecast
attribute :cuit
attribute :nombre
attribute :razon_social
attribute :tipo_social
attribute :personeria
attribute :telefono
attribute :movil
attribute :fax
attribute :email
attribute :url
attribute :tipo_pyme
attribute :calle
attribute :localidad
attribute :codigo_postal
attribute :provincia
attribute :sources, Array
index :cuit
def validate
assert_unique :cuit
end
def cuit=(value)
value = value.gsub(/[^\d]/, '') unless value.empty?
write_local(:cuit, value)
end
def url=(value)
unless value.empty?
value = "http://#{value}" unless value =~ /^https?:\/\//
value = value.downcase
end
write_local(:url, value)
end
def email=(value)
value = value.downcase unless value.empty?
write_local(:email, value)
end
def to_hash
super.merge(attributes.inject({}) { |attrs, name|
attrs[name] = self.send(name)
attrs
})
end
def self.pending
key[:pending]
end
end