lexigrapher 0.0.1 → 0.0.2
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 +16 -0
- data/lib/lexigrapher.rb +47 -12
- data/lib/lexigrapher/regexp/regexp.rb +13 -0
- data/lib/lexigrapher/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e8f39feceedd13cebe1f570f56a09cadec81f90
|
4
|
+
data.tar.gz: ef8bbb70151990be85e3e9bbfa26c8b01d19c61d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c56d713e17912dc91c9c0755b898fa87ee4f59fcae26d2e3c77bee1526b026826182e0e9aa9ffd0ed3e845d7ea05b9ecdceac66f5f7badbd68e71eafb98c8189
|
7
|
+
data.tar.gz: 193490eabd69b81b5664cbff681c173e2cf94f48cb5dce013c6f63f5512f45f572aa9382292abf5a5a04876d7399b179607c1314ec1d7fb2bd4341992bca6c23
|
data/README.md
CHANGED
@@ -13,3 +13,19 @@ Lexigrapher::Parser.new('0xFFF').type
|
|
13
13
|
```ruby
|
14
14
|
:integer
|
15
15
|
```
|
16
|
+
|
17
|
+
## What does it try and match against?
|
18
|
+
|
19
|
+
To quote the source, and to give you the parser order:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
def methods
|
23
|
+
[
|
24
|
+
:int?, :float?, :symbol?, :hash?, :array?, # Primatives
|
25
|
+
:date?, :phone?, :email?, :url?, :ipv4?, :ipv6?, :gender?, # Extensions
|
26
|
+
:str?, :nil?, :unknown? # Primitives fallback
|
27
|
+
]
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Want more checks? Log an issue and let me know!
|
data/lib/lexigrapher.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'date'
|
1
|
+
require "lexigrapher/version"
|
2
|
+
require "lexigrapher/regexp/regexp"
|
4
3
|
|
5
4
|
module Lexigrapher
|
6
5
|
class Parser
|
@@ -11,6 +10,7 @@ module Lexigrapher
|
|
11
10
|
@type = value ? try_types(methods) : :nil
|
12
11
|
end
|
13
12
|
|
13
|
+
# Tail Recurse through all methods specified
|
14
14
|
def try_types(methods)
|
15
15
|
method, remaining = methods.first, methods[1..-1]
|
16
16
|
type = self.send method
|
@@ -20,9 +20,16 @@ module Lexigrapher
|
|
20
20
|
|
21
21
|
# Define the fallthrough order. I would rather be explicit here, so as for customization.
|
22
22
|
def methods
|
23
|
-
[
|
23
|
+
[
|
24
|
+
:int?, :float?, :symbol?, :hash?, :array?, # Primatives
|
25
|
+
:date?, :phone?, :email?, :url?, :ipv4?, :ipv6?, :gender?, # Extensions
|
26
|
+
:str?, :nil?, :unknown? # Primitives fallback
|
27
|
+
]
|
24
28
|
end
|
25
29
|
|
30
|
+
# As much as I don't like Rescue for flow control, it is considerably nicer than the potential REGEXP
|
31
|
+
# that would have replaced it. The same can be said for everything using Rescue below.
|
32
|
+
|
26
33
|
def int?
|
27
34
|
:integer if Integer(v) rescue nil
|
28
35
|
end
|
@@ -35,28 +42,56 @@ module Lexigrapher
|
|
35
42
|
:symbol if v[0] == ':'
|
36
43
|
end
|
37
44
|
|
45
|
+
def date?
|
46
|
+
:date if v.match(StrRegexp::DATE)
|
47
|
+
end
|
48
|
+
|
38
49
|
def hash?
|
39
|
-
:hash if v
|
50
|
+
:hash if v.match(StrRegexp::HASH)
|
40
51
|
end
|
41
52
|
|
42
53
|
def array?
|
43
|
-
:array if v
|
54
|
+
:array if v.match(StrRegexp::ARRAY)
|
44
55
|
end
|
45
56
|
|
46
|
-
def
|
47
|
-
:
|
57
|
+
def phone?
|
58
|
+
:phone if v.match(StrRegexp::PHONE)
|
48
59
|
end
|
49
60
|
|
50
|
-
def
|
51
|
-
:
|
61
|
+
def email?
|
62
|
+
:email if v.match(StrRegexp::EMAIL)
|
52
63
|
end
|
53
64
|
|
54
|
-
def
|
55
|
-
:
|
65
|
+
def url?
|
66
|
+
:url if v.match(StrRegexp::URL)
|
67
|
+
end
|
68
|
+
|
69
|
+
def ipv4?
|
70
|
+
:ipv4 if v.match(StrRegexp::IPV4)
|
71
|
+
end
|
72
|
+
|
73
|
+
def ipv6?
|
74
|
+
:ipv6 if v.match(StrRegexp::IPV6)
|
75
|
+
end
|
76
|
+
|
77
|
+
def gender?
|
78
|
+
:gender if v.match(StrRegexp::GENDER)
|
56
79
|
end
|
57
80
|
|
81
|
+
# Fallbacks
|
82
|
+
|
58
83
|
def str?
|
59
84
|
:str if v
|
60
85
|
end
|
86
|
+
|
87
|
+
def nil?
|
88
|
+
:nil if v.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
# Emergency Fallback
|
92
|
+
|
93
|
+
def unknown?
|
94
|
+
:unknown
|
95
|
+
end
|
61
96
|
end
|
62
97
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Lexigrapher
|
2
|
+
module StrRegexp
|
3
|
+
ARRAY = /\[.+\]/
|
4
|
+
DATE = /^(?:(1[0-2]|0?[1-9])\/(3[01]|[12][0-9]|0?[1-9])|(3[01]|[12][0-9]|0?[1-9])\/(1[0-2]|0?[1-9]))\/(?:[0-9]{2})?[0-9]{2}$/
|
5
|
+
EMAIL = /^[a-zA-Z0-9_.+\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/
|
6
|
+
GENDER = /^f?e?m?(ale)?$/i
|
7
|
+
HASH = /\{.+\}/
|
8
|
+
IPV4 = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
9
|
+
IPV6 = /^(((?=.*(::))(?!.*\3.+\3))\3?|[\dA-F]{1,4}:)([\dA-F]{1,4}(\3|:\b)|\2){5}(([\dA-F]{1,4}(\3|:\b|$)|\2){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z/i
|
10
|
+
PHONE = /^\+?\d{0,}?(\s|-|\.){0,}?\(?\d{3}\)?(\s|-|\.){0,}?\d{3}(\s|-|\.){0,}?\d{4}(\s|-|\.){0,}?(ex?t?|extension)?(\s|-|\.){0,}?\d{0,}?$/
|
11
|
+
URL = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/
|
12
|
+
end
|
13
|
+
end
|
data/lib/lexigrapher/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lexigrapher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Weaver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- lexigrapher.gemspec
|
54
54
|
- lib/lexigrapher.rb
|
55
|
+
- lib/lexigrapher/regexp/regexp.rb
|
55
56
|
- lib/lexigrapher/version.rb
|
56
57
|
homepage: https://github.com/baweaver/lexigrapher
|
57
58
|
licenses:
|