typero 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eca1e5b76d83f449b63e56a1b3835ab6d8cd72cf
4
- data.tar.gz: 9cbee48fd06fecb39a47ec0e63d47dc8cf960927
3
+ metadata.gz: 6b60246c3690ede7ca8f5e449abff10f446d76a6
4
+ data.tar.gz: fade8fc6679cc675269bb47ff03f3f0b1f965ac8
5
5
  SHA512:
6
- metadata.gz: 41a600fdbb91801cf9074688f64db8455a3f49b2838f59b09e1c38735cb24378ef11a29cf77876a2d654644db460a63448f1455dcded4d659be54db0d2c6b672
7
- data.tar.gz: 58bd24891f91910d9ec634b2e91c831e9730fea15ffb971f0ab1f0e0a63ec4e79a9e997bb228a165530e753e4fe71c3b2a702be55786ad5ee56e0c8c1336111d
6
+ metadata.gz: 024ec4893a7173adef65b29d2c14eaff0ff7d8ce658a44584aaf4ee11c5ed64c8883a6914eeb737bea6dfbf92b58bc9e2e21ce9d9f59f31cf5d066ab48a232f6
7
+ data.tar.gz: bfc7263f3991580a455ddb6f819be4337569e5d3da8203a716f5d4f813cf921b41b59b24e5cd947da995b8019d57877664c25227483c42efa2cbeccce9411ad5
data/lib/typero/type.rb CHANGED
@@ -15,6 +15,12 @@ module Typero
15
15
  value
16
16
  end
17
17
 
18
+ # sometimes we want to coarce values on get
19
+ # by default just copy
20
+ def get(list)
21
+ list
22
+ end
23
+
18
24
  # if value is blank?, trigger default
19
25
  # for example set it to false for boolean type and [] for array type
20
26
  def default
@@ -51,7 +57,7 @@ module Typero
51
57
  return default
52
58
  end
53
59
  else
54
- value
60
+ get(value)
55
61
  end
56
62
  end
57
63
 
@@ -4,13 +4,17 @@ module Typero
4
4
  []
5
5
  end
6
6
 
7
+ def get(list)
8
+ list.to_a
9
+ end
10
+
7
11
  def set(value)
8
12
  value = value.to_s.split(/\s*,\s*/) unless value.class.to_s.index('Array')
9
13
  if type = @opts[:array_type]
10
14
  check_type(type)
11
15
  value.each { |el| Typero.validate!(el, type) }
12
16
  end
13
- value
17
+ value.to_a
14
18
  end
15
19
 
16
20
  def validate(list)
@@ -5,8 +5,7 @@ module Typero
5
5
  end
6
6
 
7
7
  def set(value)
8
- value = false if [0, '0', 'false'].index(value)
9
- !!value
8
+ [true, 1, '1', 'true'].index(value) ? true : false
10
9
  end
11
10
  end
12
11
  end
@@ -1,14 +1,13 @@
1
1
  module Typero
2
2
  class EmailType < Typero::Type
3
3
  def set(value)
4
- value.downcase
4
+ value.downcase.gsub(/\s+/,'+')
5
5
  end
6
6
 
7
7
  def validate(value)
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, 'is in wrong domain' unless value =~ /\.\w{2,4}$/
11
- raise TypeError, 'is in wrong format' unless value =~ /^[\w\-\.]+\@[\w\-\.]+$/i
10
+ raise TypeError, 'is in wrong format' unless value =~ /^[\+\w\-\.]+\@[\w\-\.]+$/i
12
11
  true
13
12
  end
14
13
  end
@@ -1,4 +1,4 @@
1
1
  module Typero
2
2
  # VERSION = File.read(File.dirname(__FILE__)+'/version.txt').gsub(/\s/,'').freeze
3
- VERSION = '0.2.5'
3
+ VERSION = '0.2.6'
4
4
  end
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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_blank