enotype 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +225 -5
- data/lib/enotype/de.rb +7 -0
- data/lib/enotype/en.rb +7 -0
- data/lib/enotype/es.rb +7 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 696aaec3692ebde4b659d55dfa9204c518c1ef79dbd1cb3e471b8adfefd3b2d3
|
4
|
+
data.tar.gz: 43ac82acba4c279448ce1772df426e7c5ea3171407491807d16255736e5401b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98e65e3c1ab680317b0d7c2f6fe467a21fb3aa8511e247c8eec49527072e4a24969d7e2f21ff5db911f16e3f168f164cfdf4d8feece7358ab69ff125bed6927c
|
7
|
+
data.tar.gz: 5ee2dec7a1fd2c962006a3481e845521ad03fc4ca0a6a931ec849a5913fc2d7fb8474b5b532814967fda8dc15aa220ab829861e95e5461850f3ce26fcb799785
|
data/README.md
CHANGED
@@ -1,14 +1,234 @@
|
|
1
1
|
# enotype
|
2
2
|
|
3
|
-
**A cross-language
|
3
|
+
**A cross-language type library**
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
require 'enotype'
|
7
7
|
|
8
|
-
Enotype::color('#fff') # returns
|
9
|
-
Enotype::color('#xyz') # raises
|
8
|
+
Enotype::color('#fff') # returns "#fff"
|
9
|
+
Enotype::color('#xyz') # raises "A color is required, for instance '#B6D918', '#fff' or '#01b'."
|
10
10
|
```
|
11
11
|
|
12
|
-
|
12
|
+
```ruby
|
13
|
+
require 'enotype/es' # with localized error messages
|
14
|
+
|
15
|
+
Enotype::color('#xyz') # raises "Se requiere un color, por ejemplo '#B6D918', '#fff' o '#01b'."
|
16
|
+
```
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Either add it to your `Gemfile`:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'enotype'
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it manually:
|
27
|
+
|
28
|
+
```
|
29
|
+
gem install enotype
|
30
|
+
```
|
31
|
+
|
32
|
+
## Features
|
33
|
+
|
34
|
+
- Validation and conversion of `string` representations into language-native types.
|
35
|
+
- Implemented as a collection of minimalist functions, so called *loaders*.
|
36
|
+
- Zero-cost localization (currently `de`, `en`, `es`) through statically generated code.
|
37
|
+
- Generically usable in a multitude of contexts through a plain and simple design.
|
38
|
+
- Standard type library for the [eno notation language](https://eno-lang.org).
|
39
|
+
|
40
|
+
## Documentation
|
41
|
+
|
42
|
+
### boolean
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require 'enotype'
|
46
|
+
|
47
|
+
Enotype::boolean('true') # returns true
|
48
|
+
```
|
49
|
+
|
50
|
+
`'true'` returns `true`.
|
51
|
+
`'false'` returns `false`.
|
52
|
+
`'yes'` returns `true`.
|
53
|
+
`'no'` returns `false`.
|
54
|
+
`'nope'` raises an exception.
|
55
|
+
### color
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'enotype'
|
59
|
+
|
60
|
+
Enotype::color('#abcdef') # returns '#abcdef'
|
61
|
+
```
|
62
|
+
|
63
|
+
`'#abcdef'` returns `'#abcdef'`.
|
64
|
+
`'#ABCDEF'` returns `'#ABCDEF'`.
|
65
|
+
`'#012345'` returns `'#012345'`.
|
66
|
+
`'#678'` returns `'#678'`.
|
67
|
+
`'#89a'` returns `'#89a'`.
|
68
|
+
`'#ab'` raises an exception.
|
69
|
+
`'#abcd'` raises an exception.
|
70
|
+
`'#abcde'` raises an exception.
|
71
|
+
`'#bcdefg'` raises an exception.
|
72
|
+
`'blue'` raises an exception.
|
73
|
+
### comma_separated
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
require 'enotype'
|
77
|
+
|
78
|
+
Enotype::comma_separated('one,two,three') # returns ['one', 'two', 'three']
|
79
|
+
```
|
80
|
+
|
81
|
+
`'one,two,three'` returns `['one', 'two', 'three']`.
|
82
|
+
`' one,two,three '` returns `['one', 'two', 'three']`.
|
83
|
+
`'one , two , three'` returns `['one', 'two', 'three']`.
|
84
|
+
`' one , two , three '` returns `['one', 'two', 'three']`.
|
85
|
+
`',,'` returns `['', '', '']`.
|
86
|
+
`'one two three'` returns `['one two three']`.
|
87
|
+
`'one;two;three'` returns `['one;two;three']`.
|
88
|
+
`' '` returns `['']`.
|
89
|
+
### date
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require 'enotype'
|
93
|
+
|
94
|
+
Enotype::date('1992-02-02') # returns Time.utc(1992, 2, 2)
|
95
|
+
```
|
96
|
+
|
97
|
+
`'1992-02-02'` returns `Time.utc(1992, 2, 2)`.
|
98
|
+
`'1990'` raises an exception.
|
99
|
+
`'1991-01'` raises an exception.
|
100
|
+
`'1993-03-03T1920+01:00'` raises an exception.
|
101
|
+
`'1994-04-04T1920:30+01:00'` raises an exception.
|
102
|
+
`'1995-05-05T1920:30.45+01:00'` raises an exception.
|
103
|
+
`'1996-06-06T0815:30-05:00'` raises an exception.
|
104
|
+
`'1997-07-07T1315:30Z'` raises an exception.
|
105
|
+
`'2002 12 14'` raises an exception.
|
106
|
+
`'2002-12-14 20:15'` raises an exception.
|
107
|
+
`'January'` raises an exception.
|
108
|
+
`'13:00'` raises an exception.
|
109
|
+
### datetime
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
require 'enotype'
|
113
|
+
|
114
|
+
Enotype::datetime('1990') # returns Time.utc(1990, 1, 1)
|
115
|
+
```
|
116
|
+
|
117
|
+
`'1990'` returns `Time.utc(1990, 1, 1)`.
|
118
|
+
`'1991-01'` returns `Time.utc(1991, 1, 1)`.
|
119
|
+
`'1992-02-02'` returns `Time.utc(1992, 2, 2)`.
|
120
|
+
`'1993-03-03T19:20+01:00'` returns `Time.utc(1993, 3, 3, 18, 20)`.
|
121
|
+
`'1994-04-04T19:20:30+01:00'` returns `Time.new(1994, 4, 4, 19, 20, 30, '+01:00')`.
|
122
|
+
`'1995-05-05T19:20:30.450+01:00'` returns `Time.new(1995, 5, 5, 19, 20, 30.450, '+01:00')`.
|
123
|
+
`'1996-06-06T08:15:30-05:00'` returns `Time.new(1996, 6, 6, 8, 15, 30, '-05:00')`.
|
124
|
+
`'1997-07-07T13:15:30Z'` returns `Time.utc(1997, 7, 7, 13, 15, 30)`.
|
125
|
+
`'2002 12 14'` raises an exception.
|
126
|
+
`'2002-12-14 20:15'` raises an exception.
|
127
|
+
`'January'` raises an exception.
|
128
|
+
`'13:00'` raises an exception.
|
129
|
+
### email
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
require 'enotype'
|
133
|
+
|
134
|
+
Enotype::email('john.doe@eno-lang.org') # returns 'john.doe@eno-lang.org'
|
135
|
+
```
|
136
|
+
|
137
|
+
`'john.doe@eno-lang.org'` returns `'john.doe@eno-lang.org'`.
|
138
|
+
`'john.doe@eno-lang'` raises an exception.
|
139
|
+
`'@eno-lang.org'` raises an exception.
|
140
|
+
`'john.doe@.org'` raises an exception.
|
141
|
+
### float
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
require 'enotype'
|
145
|
+
|
146
|
+
Enotype::float('42') # returns 42.0
|
147
|
+
```
|
148
|
+
|
149
|
+
`'42'` returns `42.0`.
|
150
|
+
`'-42'` returns `-42.0`.
|
151
|
+
`'42.0'` returns `42.0`.
|
152
|
+
`'42,0'` raises an exception.
|
153
|
+
`'4 2.0'` raises an exception.
|
154
|
+
`'fortytwo'` raises an exception.
|
155
|
+
### integer
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
require 'enotype'
|
159
|
+
|
160
|
+
Enotype::integer('42') # returns 42
|
161
|
+
```
|
162
|
+
|
163
|
+
`'42'` returns `42`.
|
164
|
+
`'-42'` returns `-42`.
|
165
|
+
`'42.0'` raises an exception.
|
166
|
+
`'42,0'` raises an exception.
|
167
|
+
`'4 2'` raises an exception.
|
168
|
+
`'fortytwo'` raises an exception.
|
169
|
+
### json
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
require 'enotype'
|
173
|
+
|
174
|
+
Enotype::json('{ "valid": true }') # returns { 'valid' => true }
|
175
|
+
```
|
176
|
+
|
177
|
+
`'{ "valid": true }'` returns `{ 'valid' => true }`.
|
178
|
+
`'42'` returns `42`.
|
179
|
+
`'["valid", true]'` returns `['valid', true]`.
|
180
|
+
`'invalid'` raises an exception.
|
181
|
+
`'{ invalid: true }'` raises an exception.
|
182
|
+
`'{ "invalid": true, }'` raises an exception.
|
183
|
+
### lat_lng
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
require 'enotype'
|
187
|
+
|
188
|
+
Enotype::lat_lng('48.205870, 16.413690') # returns { lat: 48.205870, lng: 16.413690 }
|
189
|
+
```
|
190
|
+
|
191
|
+
`'48.205870, 16.413690'` returns `{ lat: 48.205870, lng: 16.413690 }`.
|
192
|
+
`'41.25, -120.9762'` returns `{ lat: 41.25, lng: -120.9762 }`.
|
193
|
+
`'-31.96, 115.84'` returns `{ lat: -31.96, lng: 115.84 }`.
|
194
|
+
`'90, 0'` returns `{ lat: 90, lng: 0 }`.
|
195
|
+
`' 0 , 0 '` returns `{ lat: 0, lng: 0 }`.
|
196
|
+
`'-0,-0'` returns `{ lat: -0, lng: -0 }`.
|
197
|
+
`'1000,10'` raises an exception.
|
198
|
+
`'10,1000'` raises an exception.
|
199
|
+
`'48.205870,'` raises an exception.
|
200
|
+
`', 16.413690'` raises an exception.
|
201
|
+
`'48,205870, 16,413690'` raises an exception.
|
202
|
+
### slug
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
require 'enotype'
|
206
|
+
|
207
|
+
Enotype::slug('eno-lang-article') # returns 'eno-lang-article'
|
208
|
+
```
|
209
|
+
|
210
|
+
`'eno-lang-article'` returns `'eno-lang-article'`.
|
211
|
+
`'eno_lang_article'` returns `'eno_lang_article'`.
|
212
|
+
`'eno-lang-article!'` raises an exception.
|
213
|
+
`'%eno-lang-article'` raises an exception.
|
214
|
+
`'eno lang article'` raises an exception.
|
215
|
+
`'enö-läng-ärticle'` raises an exception.
|
216
|
+
`'énó-láng-ártíclé'` raises an exception.
|
217
|
+
### url
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
require 'enotype'
|
221
|
+
|
222
|
+
Enotype::url('http://www.valid.com') # returns 'http://www.valid.com'
|
223
|
+
```
|
13
224
|
|
14
|
-
|
225
|
+
`'http://www.valid.com'` returns `'http://www.valid.com'`.
|
226
|
+
`'https://valid.com'` returns `'https://valid.com'`.
|
227
|
+
`'https://www.valid.com'` returns `'https://www.valid.com'`.
|
228
|
+
`'invalid'` raises an exception.
|
229
|
+
`'www.invalid'` raises an exception.
|
230
|
+
`'www.invalid.com'` raises an exception.
|
231
|
+
`'htp://www.invalid.com'` raises an exception.
|
232
|
+
`'http:/invalid.com'` raises an exception.
|
233
|
+
`'https//invalid.com'` raises an exception.
|
234
|
+
`'https://invalid'` raises an exception.
|
data/lib/enotype/de.rb
CHANGED
@@ -7,6 +7,7 @@ EMAIL_REGEXP = /^\s*[^@\s]+@[^@\s]+\.[^@\s]+\s*$/
|
|
7
7
|
FLOAT_REGEXP = /^\s*-?\d+(\.\d+)?\s*$/
|
8
8
|
INTEGER_REGEXP = /^\s*-?\d+\s*$/
|
9
9
|
LAT_LNG_REGEXP = /^\s*(-?\d{1,3}(?:\.\d+)?)\s*,\s*(-?\d{1,3}(?:\.\d+)?)\s*$/
|
10
|
+
SLUG_REGEXP = /^[0-9a-z\-_]+$/
|
10
11
|
URL_REGEXP = /^\s*https?:\/\/[^\s.]+\.\S+\s*$/
|
11
12
|
|
12
13
|
module Enotype
|
@@ -95,6 +96,12 @@ module Enotype
|
|
95
96
|
{ lat: match[1].to_f, lng: match[2].to_f }
|
96
97
|
end
|
97
98
|
|
99
|
+
def self.slug(value)
|
100
|
+
raise 'Ein Slug wie zum Beispiel \'blog_post\', \'eno-notation\' oder \'62-dinge\' ist erforderlich - nur die Zeichen a-z, 0-9, \'-\' und \'_\' sind erlaubt.' unless value.match(SLUG_REGEXP)
|
101
|
+
|
102
|
+
value
|
103
|
+
end
|
104
|
+
|
98
105
|
def self.url(value)
|
99
106
|
raise 'Eine valide URL ist erforderlich, zum Beispiel \'https://eno-lang.org\'.' unless value.match(URL_REGEXP)
|
100
107
|
|
data/lib/enotype/en.rb
CHANGED
@@ -7,6 +7,7 @@ EMAIL_REGEXP = /^\s*[^@\s]+@[^@\s]+\.[^@\s]+\s*$/
|
|
7
7
|
FLOAT_REGEXP = /^\s*-?\d+(\.\d+)?\s*$/
|
8
8
|
INTEGER_REGEXP = /^\s*-?\d+\s*$/
|
9
9
|
LAT_LNG_REGEXP = /^\s*(-?\d{1,3}(?:\.\d+)?)\s*,\s*(-?\d{1,3}(?:\.\d+)?)\s*$/
|
10
|
+
SLUG_REGEXP = /^[0-9a-z\-_]+$/
|
10
11
|
URL_REGEXP = /^\s*https?:\/\/[^\s.]+\.\S+\s*$/
|
11
12
|
|
12
13
|
module Enotype
|
@@ -95,6 +96,12 @@ module Enotype
|
|
95
96
|
{ lat: match[1].to_f, lng: match[2].to_f }
|
96
97
|
end
|
97
98
|
|
99
|
+
def self.slug(value)
|
100
|
+
raise 'A slug like for instance \'blog_post\', \'eno-notation\' or \'62-things\' is required - only the characters a-z, 0-9, \'-\' und \'_\' are allowed.' unless value.match(SLUG_REGEXP)
|
101
|
+
|
102
|
+
value
|
103
|
+
end
|
104
|
+
|
98
105
|
def self.url(value)
|
99
106
|
raise 'A valid URL is required, for instance \'https://eno-lang.org\'.' unless value.match(URL_REGEXP)
|
100
107
|
|
data/lib/enotype/es.rb
CHANGED
@@ -7,6 +7,7 @@ EMAIL_REGEXP = /^\s*[^@\s]+@[^@\s]+\.[^@\s]+\s*$/
|
|
7
7
|
FLOAT_REGEXP = /^\s*-?\d+(\.\d+)?\s*$/
|
8
8
|
INTEGER_REGEXP = /^\s*-?\d+\s*$/
|
9
9
|
LAT_LNG_REGEXP = /^\s*(-?\d{1,3}(?:\.\d+)?)\s*,\s*(-?\d{1,3}(?:\.\d+)?)\s*$/
|
10
|
+
SLUG_REGEXP = /^[0-9a-z\-_]+$/
|
10
11
|
URL_REGEXP = /^\s*https?:\/\/[^\s.]+\.\S+\s*$/
|
11
12
|
|
12
13
|
module Enotype
|
@@ -95,6 +96,12 @@ module Enotype
|
|
95
96
|
{ lat: match[1].to_f, lng: match[2].to_f }
|
96
97
|
end
|
97
98
|
|
99
|
+
def self.slug(value)
|
100
|
+
raise 'Se requiere un slug como por ejemplo \'blog_post\', \'eno-notacion\' o \'62-cosas\' - solo los caracteres a-z, 0-9, \'-\' und \'_\' son permitidos.' unless value.match(SLUG_REGEXP)
|
101
|
+
|
102
|
+
value
|
103
|
+
end
|
104
|
+
|
98
105
|
def self.url(value)
|
99
106
|
raise 'Se requiere un URL valido, por ejemplo \'https://eno-lang.org\'.' unless value.match(URL_REGEXP)
|
100
107
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enotype
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Repp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.8'
|
27
|
-
description:
|
28
|
-
|
27
|
+
description: Validation and conversion of `string` representations into language-native
|
28
|
+
types
|
29
29
|
email: simon@fdpl.io
|
30
30
|
executables: []
|
31
31
|
extensions: []
|
@@ -37,7 +37,7 @@ files:
|
|
37
37
|
- lib/enotype/de.rb
|
38
38
|
- lib/enotype/en.rb
|
39
39
|
- lib/enotype/es.rb
|
40
|
-
homepage: https://eno-lang.org/
|
40
|
+
homepage: https://eno-lang.org/enotype/
|
41
41
|
licenses:
|
42
42
|
- MIT
|
43
43
|
metadata: {}
|
@@ -60,5 +60,5 @@ rubyforge_project:
|
|
60
60
|
rubygems_version: 2.7.8
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
|
-
summary: A cross-language
|
63
|
+
summary: A cross-language type library
|
64
64
|
test_files: []
|