simple_pattern 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d337027b07ac8ae1379fcd30852811b416a70bd2
4
+ data.tar.gz: 46d1ebb8dc1ea5b54313d598b55765a652410b2b
5
+ SHA512:
6
+ metadata.gz: e6fb5ece7c2b683b7ade9ad0aa7e8fabcade95636b1a39914988e43f9bdc0b779424fc9d205e923100612faaade41a8d47a15c461a831af0360857aa01ad1660
7
+ data.tar.gz: 58a47c8f41447e4cb16dac4a4dabe4925445d4a27537f6fd5d8d576cda9612dad8223bc0a2d65e47cf09186c73d071aa974bbb3ea866d679e91470ca4e961912
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.10
6
+ - 2.2.5
7
+ - 2.3.1
8
+ - ruby-head
9
+ - jruby-1.7.25
10
+ - jruby-9.1.0.0
11
+ - jruby-head
12
+ - rbx-2
13
+ before_install: gem install bundler -v 1.12.5
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: ruby-head
17
+ - rvm: jruby-1.7.25
18
+ - rvm: jruby-9.1.0.0
19
+ - rvm: jruby-head
20
+ - rvm: rbx-2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_pattern.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The zlib license (Zlib)
2
+
3
+ Copyright (c) 2016 Tatsuya Otsuka
4
+
5
+ This software is provided 'as-is', without any express or implied
6
+ warranty. In no event will the authors be held liable for any damages
7
+ arising from the use of this software.
8
+
9
+ Permission is granted to anyone to use this software for any purpose,
10
+ including commercial applications, and to alter it and redistribute it
11
+ freely, subject to the following restrictions:
12
+
13
+ 1. The origin of this software must not be misrepresented; you must not
14
+ claim that you wrote the original software. If you use this software
15
+ in a product, an acknowledgment in the product documentation would be
16
+ appreciated but is not required.
17
+
18
+ 2. Altered source versions must be plainly marked as such, and must not be
19
+ misrepresented as being the original software.
20
+
21
+ 3. This notice may not be removed or altered from any source
22
+ distribution.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # SimplePattern
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/simple_pattern.svg)](http://badge.fury.io/rb/simple_pattern)
4
+ [![Build Status](https://travis-ci.org/Tatzyr/simple_pattern.svg?branch=master)](https://travis-ci.org/Tatzyr/simple_pattern)
5
+ [![Code Climate](https://codeclimate.com/github/Tatzyr/simple_pattern/badges/gpa.svg)](https://codeclimate.com/github/Tatzyr/simple_pattern)
6
+ [![Test Coverage](https://codeclimate.com/github/Tatzyr/simple_pattern/badges/coverage.svg)](https://codeclimate.com/github/Tatzyr/simple_pattern/coverage)
7
+ [![Dependency Status](https://gemnasium.com/Tatzyr/simple_pattern.svg)](https://gemnasium.com/Tatzyr/simple_pattern)
8
+
9
+ Very simple and plain pattern matching library for Ruby
10
+
11
+ ## Synopsis
12
+
13
+ ```ruby
14
+ require "simple_pattern"
15
+
16
+ All = SimplePattern::All
17
+ Any = SimplePattern::Any
18
+ Not = SimplePattern::Not
19
+
20
+ words = [
21
+ ["the", :english], # English stopword
22
+ ["little", :english], # English word
23
+ ["Schrödinger", :german], # German word
24
+ ["rendezvous", :french], # French word
25
+ ]
26
+
27
+ words.each do |word|
28
+ case word
29
+ when SimplePattern[Any["a", "an", "the"], :english]
30
+ puts "English stopword"
31
+ when SimplePattern[Any, :english]
32
+ puts "English word"
33
+ when SimplePattern[Any, Not[:french]]
34
+ puts "German word"
35
+ else
36
+ puts "French word"
37
+ end
38
+ end
39
+ ```
40
+
41
+ More examples are at [`spec/simple_pattern_spec.rb`](https://github.com/Tatzyr/simple_pattern/blob/master/spec/simple_pattern_spec.rb).
42
+
43
+ ## Installation
44
+
45
+ ```
46
+ $ gem install simple_pattern
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Tatzyr/simple_pattern.
58
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_pattern"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # -*- frozen_string_literal: true -*-
2
+
3
+ class SimplePattern < Array
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "simple_pattern/version"
5
+
6
+ class SimplePattern < Array
7
+ def ===(other)
8
+ zip(other).all? {|a, b| a === b }
9
+ end
10
+
11
+ class All < Array
12
+ def ===(other)
13
+ all? {|a| a === other }
14
+ end
15
+ end
16
+
17
+ class Any < Array
18
+ def self.===(other)
19
+ true
20
+ end
21
+
22
+ def ===(other)
23
+ any? {|a| a === other }
24
+ end
25
+ end
26
+
27
+ class Not < Array
28
+ def ===(other)
29
+ !any? {|a| a === other }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_pattern/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_pattern"
8
+ spec.version = SimplePattern::VERSION
9
+ spec.authors = ["Tatsuya Otsuka"]
10
+ spec.email = ["tatzyr@gmail.com"]
11
+
12
+ spec.summary = %q{Very simple and plain pattern matching library for Ruby}
13
+ spec.homepage = "https://github.com/Tatzyr/simple_pattern"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "codeclimate-test-reporter"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_pattern
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tatsuya Otsuka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codeclimate-test-reporter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - tatzyr@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/simple_pattern.rb
86
+ - lib/simple_pattern/version.rb
87
+ - simple_pattern.gemspec
88
+ homepage: https://github.com/Tatzyr/simple_pattern
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Very simple and plain pattern matching library for Ruby
111
+ test_files: []