typed-matcher 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.irbrc ADDED
@@ -0,0 +1,3 @@
1
+ lib = File.join(File.dirname(__FILE__),'lib')
2
+ $:.unshift(lib) unless $:.include?(lib)
3
+ require 'typed-matcher'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in typed-matcher.gemspec
4
+ gemspec
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,10 @@
1
+ require "delegate"
2
+ require "typed-matcher/version"
3
+
4
+ module Typed
5
+ extend self
6
+ end
7
+
8
+ %w{group matcher}.each do |f|
9
+ require File.join(File.dirname(__FILE__),'typed-matcher',f)
10
+ end
@@ -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,10 @@
1
+ module Typed
2
+ class Matcher < SimpleDelegator
3
+ attr_reader :type
4
+
5
+ def initialize type, obj
6
+ super(obj)
7
+ @type = type
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Typed
2
+ VERSION = "0.0.1"
3
+ 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
+