enotype 0.3.0 → 0.3.1

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
  SHA256:
3
- metadata.gz: 7c84e902e9b398c4d93cc534301ee414c6dda73eecd051088d0d050e15a2bd65
4
- data.tar.gz: c5c47fe3b59804e2b1b13093aedec95c6a73a499c9189ab38d4fb560457ac505
3
+ metadata.gz: 1946d9c86abd80716b91a000c8b648455c07c8e2b4b31bbfbe914d4e7298426e
4
+ data.tar.gz: 24c13217e0e7c18bcf51bb94fab8f418ff3a86e2faacfd3a2a45a95bd1745333
5
5
  SHA512:
6
- metadata.gz: 2c56dae8fca628ca7242adc567b388c5e7e587df97d141bddcedb9c8ec3407a11a511950d1bc6bd97334437044c0f0cbd696903a42875847dfa3c63f75801d7c
7
- data.tar.gz: af234ae4de9952567ee6c2bfeb90b445e2537209f7d071a3a49d929e80f024300b69992ca291e1b2b733d3aa648904583350bf3c8bf12c1f6c3e8210d4525cb2
6
+ metadata.gz: 15fd2a6595095035097face41369663ff233845d360b456801adcca84f487ede01b011f6bd0f5bf472b6cd431f3e64b345dfead2348c18c77ff0b30e1eba8dc3
7
+ data.tar.gz: 6da1878ddd2ba30b33a4bb94e27682ff285be5efe5c536923185f28458307b7b7b19ec520959d40969e8ace885b9f5343ef5e569ba5449e9956d41f79d70333d
data/README.md CHANGED
@@ -5,14 +5,14 @@
5
5
  ```ruby
6
6
  require 'enotype'
7
7
 
8
- Enotype::color('#fff') # returns "#fff"
9
- Enotype::color('#xyz') # raises "A color is required, for instance '#B6D918', '#fff' or '#01b'."
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
13
+ require 'enotype/es' # with localized error messages
14
14
 
15
- Enotype::color('#xyz') # raises "Se requiere un color, por ejemplo '#B6D918', '#fff' o '#01b'."
15
+ Enotype.color('#xyz') # raises "Se requiere un color, por ejemplo '#B6D918', '#fff' o '#01b'."
16
16
  ```
17
17
 
18
18
  ## Installation
@@ -44,7 +44,7 @@ gem install enotype
44
44
  ```ruby
45
45
  require 'enotype'
46
46
 
47
- Enotype::boolean('true') # returns true
47
+ Enotype.boolean('true') # returns true
48
48
  ```
49
49
 
50
50
  `'true'` returns `true`.
@@ -57,7 +57,7 @@ Enotype::boolean('true') # returns true
57
57
  ```ruby
58
58
  require 'enotype'
59
59
 
60
- Enotype::color('#abcdef') # returns '#abcdef'
60
+ Enotype.color('#abcdef') # returns '#abcdef'
61
61
  ```
62
62
 
63
63
  `'#abcdef'` returns `'#abcdef'`.
@@ -75,7 +75,7 @@ Enotype::color('#abcdef') # returns '#abcdef'
75
75
  ```ruby
76
76
  require 'enotype'
77
77
 
78
- Enotype::comma_separated('one,two,three') # returns ['one', 'two', 'three']
78
+ Enotype.comma_separated('one,two,three') # returns ['one', 'two', 'three']
79
79
  ```
80
80
 
81
81
  `'one,two,three'` returns `['one', 'two', 'three']`.
@@ -91,7 +91,7 @@ Enotype::comma_separated('one,two,three') # returns ['one', 'two', 'three']
91
91
  ```ruby
92
92
  require 'enotype'
93
93
 
94
- Enotype::date('1992-02-02') # returns Time.utc(1992, 2, 2)
94
+ Enotype.date('1992-02-02') # returns Time.utc(1992, 2, 2)
95
95
  ```
96
96
 
97
97
  `'1992-02-02'` returns `Time.utc(1992, 2, 2)`.
@@ -111,7 +111,7 @@ Enotype::date('1992-02-02') # returns Time.utc(1992, 2, 2)
111
111
  ```ruby
112
112
  require 'enotype'
113
113
 
114
- Enotype::datetime('1990') # returns Time.utc(1990, 1, 1)
114
+ Enotype.datetime('1990') # returns Time.utc(1990, 1, 1)
115
115
  ```
116
116
 
117
117
  `'1990'` returns `Time.utc(1990, 1, 1)`.
@@ -131,7 +131,7 @@ Enotype::datetime('1990') # returns Time.utc(1990, 1, 1)
131
131
  ```ruby
132
132
  require 'enotype'
133
133
 
134
- Enotype::email('john.doe@eno-lang.org') # returns 'john.doe@eno-lang.org'
134
+ Enotype.email('john.doe@eno-lang.org') # returns 'john.doe@eno-lang.org'
135
135
  ```
136
136
 
137
137
  `'john.doe@eno-lang.org'` returns `'john.doe@eno-lang.org'`.
@@ -143,7 +143,7 @@ Enotype::email('john.doe@eno-lang.org') # returns 'john.doe@eno-lang.org'
143
143
  ```ruby
144
144
  require 'enotype'
145
145
 
146
- Enotype::float('42') # returns 42.0
146
+ Enotype.float('42') # returns 42.0
147
147
  ```
148
148
 
149
149
  `'42'` returns `42.0`.
@@ -157,7 +157,7 @@ Enotype::float('42') # returns 42.0
157
157
  ```ruby
158
158
  require 'enotype'
159
159
 
160
- Enotype::integer('42') # returns 42
160
+ Enotype.integer('42') # returns 42
161
161
  ```
162
162
 
163
163
  `'42'` returns `42`.
@@ -171,7 +171,7 @@ Enotype::integer('42') # returns 42
171
171
  ```ruby
172
172
  require 'enotype'
173
173
 
174
- Enotype::ipv4('0.0.0.0') # returns '0.0.0.0'
174
+ Enotype.ipv4('0.0.0.0') # returns '0.0.0.0'
175
175
  ```
176
176
 
177
177
  `'0.0.0.0'` returns `'0.0.0.0'`.
@@ -186,7 +186,7 @@ Enotype::ipv4('0.0.0.0') # returns '0.0.0.0'
186
186
  ```ruby
187
187
  require 'enotype'
188
188
 
189
- Enotype::json('{ "valid": true }') # returns { 'valid' => true }
189
+ Enotype.json('{ "valid": true }') # returns { 'valid' => true }
190
190
  ```
191
191
 
192
192
  `'{ "valid": true }'` returns `{ 'valid' => true }`.
@@ -200,7 +200,7 @@ Enotype::json('{ "valid": true }') # returns { 'valid' => true }
200
200
  ```ruby
201
201
  require 'enotype'
202
202
 
203
- Enotype::lat_lng('48.205870, 16.413690') # returns { lat: 48.205870, lng: 16.413690 }
203
+ Enotype.lat_lng('48.205870, 16.413690') # returns { lat: 48.205870, lng: 16.413690 }
204
204
  ```
205
205
 
206
206
  `'48.205870, 16.413690'` returns `{ lat: 48.205870, lng: 16.413690 }`.
@@ -219,7 +219,7 @@ Enotype::lat_lng('48.205870, 16.413690') # returns { lat: 48.205870, lng: 16.413
219
219
  ```ruby
220
220
  require 'enotype'
221
221
 
222
- Enotype::slug('eno-lang-article') # returns 'eno-lang-article'
222
+ Enotype.slug('eno-lang-article') # returns 'eno-lang-article'
223
223
  ```
224
224
 
225
225
  `'eno-lang-article'` returns `'eno-lang-article'`.
@@ -234,7 +234,7 @@ Enotype::slug('eno-lang-article') # returns 'eno-lang-article'
234
234
  ```ruby
235
235
  require 'enotype'
236
236
 
237
- Enotype::url('http://www.valid.com') # returns 'http://www.valid.com'
237
+ Enotype.url('http://www.valid.com') # returns 'http://www.valid.com'
238
238
  ```
239
239
 
240
240
  `'http://www.valid.com'` returns `'http://www.valid.com'`.
@@ -246,4 +246,26 @@ Enotype::url('http://www.valid.com') # returns 'http://www.valid.com'
246
246
  `'htp://www.invalid.com'` raises an exception.
247
247
  `'http:/invalid.com'` raises an exception.
248
248
  `'https//invalid.com'` raises an exception.
249
- `'https://invalid'` raises an exception.
249
+ `'https://invalid'` raises an exception.
250
+
251
+ ### procs
252
+
253
+ Not a loader but a helper method to obtain some or all loaders wrapped in a
254
+ hash of procs, which allows to pass them around easily (this is mainly
255
+ intended for registering loaders with
256
+ [enolib](https://eno-lang.org/enolib)).
257
+
258
+ ```ruby
259
+ require 'enotype'
260
+
261
+ # Get all loaders wrapped in a hash of procs
262
+ loaders = Enotype.procs
263
+ loaders[:boolean].call('true') # returns true
264
+
265
+ # Get only the color and float loaders wrapped in a hash of procs
266
+ loaders = Enotype.procs(:color, :float)
267
+ loaders[:float].call('42.0') # returns 42.0
268
+
269
+ # Registering loaders with enolib (main intended usage)
270
+ Enolib.register(Enotype.procs(:color, :float))
271
+ ```
@@ -120,4 +120,23 @@ module Enotype
120
120
 
121
121
  value
122
122
  end
123
+
124
+ def self.procs(*explicitly_requested)
125
+ available = self.singleton_methods.reject { |name| name == :procs }
126
+
127
+ if explicitly_requested.empty?
128
+ available.to_h do |name|
129
+ [name, Proc.new { |value| self.send(name, value) }]
130
+ end
131
+ else
132
+ explicitly_requested.to_h do |name|
133
+ unless available.include?(name)
134
+ list = available.map { |name| ":#{name}" }.join(', ')
135
+ raise "Enotype does not provide :#{name}, available are: #{list}"
136
+ end
137
+
138
+ [name, Proc.new { |value| self.send(name, value) }]
139
+ end
140
+ end
141
+ end
123
142
  end
@@ -120,4 +120,23 @@ module Enotype
120
120
 
121
121
  value
122
122
  end
123
+
124
+ def self.procs(*explicitly_requested)
125
+ available = self.singleton_methods.reject { |name| name == :procs }
126
+
127
+ if explicitly_requested.empty?
128
+ available.to_h do |name|
129
+ [name, Proc.new { |value| self.send(name, value) }]
130
+ end
131
+ else
132
+ explicitly_requested.to_h do |name|
133
+ unless available.include?(name)
134
+ list = available.map { |name| ":#{name}" }.join(', ')
135
+ raise "Enotype does not provide :#{name}, available are: #{list}"
136
+ end
137
+
138
+ [name, Proc.new { |value| self.send(name, value) }]
139
+ end
140
+ end
141
+ end
123
142
  end
@@ -120,4 +120,23 @@ module Enotype
120
120
 
121
121
  value
122
122
  end
123
+
124
+ def self.procs(*explicitly_requested)
125
+ available = self.singleton_methods.reject { |name| name == :procs }
126
+
127
+ if explicitly_requested.empty?
128
+ available.to_h do |name|
129
+ [name, Proc.new { |value| self.send(name, value) }]
130
+ end
131
+ else
132
+ explicitly_requested.to_h do |name|
133
+ unless available.include?(name)
134
+ list = available.map { |name| ":#{name}" }.join(', ')
135
+ raise "Enotype does not provide :#{name}, available are: #{list}"
136
+ end
137
+
138
+ [name, Proc.new { |value| self.send(name, value) }]
139
+ end
140
+ end
141
+ end
123
142
  end
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.3.0
4
+ version: 0.3.1
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-03-22 00:00:00.000000000 Z
11
+ date: 2019-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -41,7 +41,7 @@ licenses:
41
41
  - MIT
42
42
  metadata:
43
43
  bug_tracker_uri: https://github.com/eno-lang/enotype/issues
44
- changelog_uri: https://github.com/eno-lang/enotype/CHANGELOG.md
44
+ changelog_uri: https://github.com/eno-lang/enotype/blob/master/CHANGELOG.md
45
45
  documentation_uri: https://eno-lang.org/enotype/
46
46
  homepage_uri: https://eno-lang.org/enotype/
47
47
  source_code_uri: https://github.com/eno-lang/enotype/