typero 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.version +1 -1
- data/lib/typero.rb +27 -0
- data/lib/typero/type.rb +1 -1
- data/lib/typero/type/email.rb +1 -1
- data/lib/typero/type/label.rb +1 -1
- data/lib/typero/type/oib.rb +29 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eaa8278b3b0dde68e1c8f2ff0ebed2715cc21caee65e4eace4d2dafd69b96bbc
|
4
|
+
data.tar.gz: fddf1feee206bb971713ed9df6819cfef93abb457b1ed141ecf1d43bde74d462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ad494feec708f0886a9396b8311433ea0eb2310ace9ba761c9e1ae8d7c19995bac61dd938beb6a201666f16c3a09b5788e1b0ba499fc9c742ebed878aa919ab
|
7
|
+
data.tar.gz: 6db00aae4495818d03f5dabb09eb1f19d43bfcecbd05c0528b8dc136f818643731f0e4f7635aa4ffecbb8b7a59d90af30da94ca2a9114ed7f10369192ab149af
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/lib/typero.rb
CHANGED
@@ -31,6 +31,13 @@ class Typero
|
|
31
31
|
h[field]
|
32
32
|
end
|
33
33
|
|
34
|
+
# Typero.set(:label, 'Foo bar') -> "foo-bar"
|
35
|
+
def set type, value, opts={}
|
36
|
+
klass = 'Typero::%sType' % type.to_s.gsub(/[^\w]/,'').classify
|
37
|
+
check = klass.constantize.new value, opts
|
38
|
+
check.set
|
39
|
+
end
|
40
|
+
|
34
41
|
def cache
|
35
42
|
@@cache ||= {}
|
36
43
|
end
|
@@ -45,6 +52,23 @@ class Typero
|
|
45
52
|
instance_exec &block if block
|
46
53
|
end
|
47
54
|
|
55
|
+
# convert
|
56
|
+
# integer :age
|
57
|
+
# set :age, type: :integer
|
58
|
+
# email :email
|
59
|
+
# set :email, [:emails]
|
60
|
+
# email [:emails]
|
61
|
+
def method_missing name, *args, &block
|
62
|
+
field = args.shift
|
63
|
+
|
64
|
+
if field.class == Array
|
65
|
+
field = field.first
|
66
|
+
name = [name]
|
67
|
+
end
|
68
|
+
|
69
|
+
set field, type=name, *args
|
70
|
+
end
|
71
|
+
|
48
72
|
# coerce opts values
|
49
73
|
def parse_option opts
|
50
74
|
opts[:type] ||= 'string'
|
@@ -67,6 +91,9 @@ class Typero
|
|
67
91
|
|
68
92
|
# used in dsl to define value
|
69
93
|
def set field, type=String, opts={}
|
94
|
+
klass = '::Typero::%sType' % type.to_s.gsub(/[^\w]/,'').classify
|
95
|
+
klass.constantize
|
96
|
+
|
70
97
|
opts = type.is_a?(Hash) ? type : opts.merge(type: type)
|
71
98
|
|
72
99
|
@rules[field] = parse_option opts
|
data/lib/typero/type.rb
CHANGED
data/lib/typero/type/email.rb
CHANGED
@@ -7,7 +7,7 @@ class Typero::EmailType < Typero::Type
|
|
7
7
|
def validate
|
8
8
|
raise TypeError, 'is not having at least 8 characters' unless @value.to_s.length > 7
|
9
9
|
raise TypeError, 'is missing @' unless @value.include?('@')
|
10
|
-
raise TypeError,
|
10
|
+
# raise TypeError, "[#{@value}] is in wrong format" unless @value =~ /^[\+\w\-\.]+\@[\w\-\.]+$/i
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
data/lib/typero/type/label.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
class Typero::OibType < Typero::Type
|
2
|
+
def check? oib
|
3
|
+
oib = oib.to_s
|
4
|
+
|
5
|
+
return false if (oib =~ /\d{11}/) != 0
|
6
|
+
return false if oib.length != 11
|
7
|
+
|
8
|
+
a = 10
|
9
|
+
(0..9).each do |i|
|
10
|
+
a = (a + oib[i,1].to_i) % 10
|
11
|
+
a = 10 if a == 0
|
12
|
+
a = (a * 2) % 11
|
13
|
+
end
|
14
|
+
|
15
|
+
kontrolna = 11 - a
|
16
|
+
kontrolna = 0 if kontrolna == 10
|
17
|
+
|
18
|
+
kontrolna == oib[10,1].to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
def set
|
22
|
+
@value = check?(@value) ? @value.to_i : nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate
|
26
|
+
raise TypeError.new('Not an OIB') unless check?(@value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fast_blank
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- "./lib/typero/type/hash.rb"
|
42
42
|
- "./lib/typero/type/integer.rb"
|
43
43
|
- "./lib/typero/type/label.rb"
|
44
|
+
- "./lib/typero/type/oib.rb"
|
44
45
|
- "./lib/typero/type/string.rb"
|
45
46
|
- "./lib/typero/type/url.rb"
|
46
47
|
homepage: https://github.com/dux/typero
|
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
64
|
version: '0'
|
64
65
|
requirements: []
|
65
66
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.7.5
|
67
68
|
signing_key:
|
68
69
|
specification_version: 4
|
69
70
|
summary: Ruby type system
|