typed-matcher 0.0.1
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.
- data/.gitignore +4 -0
- data/.irbrc +3 -0
- data/Gemfile +4 -0
- data/README.md +15 -0
- data/Rakefile +1 -0
- data/lib/typed-matcher.rb +10 -0
- data/lib/typed-matcher/group.rb +25 -0
- data/lib/typed-matcher/matcher.rb +10 -0
- data/lib/typed-matcher/version.rb +3 -0
- data/typed-matcher.gemspec +24 -0
- metadata +75 -0
data/.gitignore
ADDED
data/.irbrc
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Typed Matcher
|
2
|
+
=============
|
3
|
+
|
4
|
+
A simple class for determining what type an object is
|
5
|
+
|
6
|
+
Example
|
7
|
+
-------
|
8
|
+
|
9
|
+
require "typed-matcher"
|
10
|
+
group = Typed::Group.new
|
11
|
+
group.register :vowel, /(a|e|i|o|u)/i, /(y)/i
|
12
|
+
group.register :z, /(z)/i
|
13
|
+
m = group.match('a')
|
14
|
+
m[1] #=> 'a'
|
15
|
+
m.type #=> :vowel
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Typed
|
2
|
+
class Group
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@types = Hash.new {|h,k| h[k]=[]}
|
6
|
+
end
|
7
|
+
|
8
|
+
def register type, *regexs
|
9
|
+
regexs.flatten!
|
10
|
+
|
11
|
+
@types[type] |= regexs
|
12
|
+
end
|
13
|
+
|
14
|
+
def match str
|
15
|
+
@types.each do |type,regexes|
|
16
|
+
regexes.each do |regex|
|
17
|
+
if m = str.match(regex)
|
18
|
+
return Matcher.new(type,m)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "typed-matcher/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "typed-matcher"
|
7
|
+
s.version = Typed::VERSION
|
8
|
+
s.authors = ["Tal Atlas"]
|
9
|
+
s.email = ["tatlas@giltcity.com"]
|
10
|
+
s.homepage = "https://github.com/Talby/Typed-Matcher"
|
11
|
+
s.summary = %q{Detect what type a string is}
|
12
|
+
s.description = %q{Define groups of matchers to determine what type of item a strng is}
|
13
|
+
|
14
|
+
s.rubyforge_project = "typed-matcher"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: typed-matcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tal Atlas
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-05 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Define groups of matchers to determine what type of item a strng is
|
22
|
+
email:
|
23
|
+
- tatlas@giltcity.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- .irbrc
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/typed-matcher.rb
|
37
|
+
- lib/typed-matcher/group.rb
|
38
|
+
- lib/typed-matcher/matcher.rb
|
39
|
+
- lib/typed-matcher/version.rb
|
40
|
+
- typed-matcher.gemspec
|
41
|
+
homepage: https://github.com/Talby/Typed-Matcher
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: typed-matcher
|
70
|
+
rubygems_version: 1.8.8
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Detect what type a string is
|
74
|
+
test_files: []
|
75
|
+
|