pic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.ruby +57 -0
  2. data/HISTORY.md +12 -0
  3. data/LICENSE.txt +27 -0
  4. data/README.md +38 -0
  5. data/lib/pic.rb +76 -0
  6. data/spec/pic.md +27 -0
  7. metadata +104 -0
data/.ruby ADDED
@@ -0,0 +1,57 @@
1
+ ---
2
+ source:
3
+ - meta
4
+ authors:
5
+ - name: Thomas Sawyer
6
+ email: transfire@gmail.com
7
+ copyrights:
8
+ - holder: Rubyworks
9
+ year: '2011'
10
+ license: BSD-2-Clause
11
+ requirements:
12
+ - name: qed
13
+ groups:
14
+ - test
15
+ development: true
16
+ - name: ae
17
+ groups:
18
+ - test
19
+ development: true
20
+ - name: detroit
21
+ groups:
22
+ - build
23
+ development: true
24
+ - name: reap
25
+ groups:
26
+ - build
27
+ development: true
28
+ dependencies: []
29
+ alternatives: []
30
+ conflicts: []
31
+ repositories:
32
+ - uri: git://github.com/proutils/pic.git
33
+ scm: git
34
+ name: upstream
35
+ resources:
36
+ home: http://rubyworks.github.com/pic
37
+ code: http://github.com/rubyworks/pic
38
+ bugs: http://github.com/rubyworks/pic/issues
39
+ mail: http://groups.google.com/groups/rubyworks-mailinglist
40
+ chat: irc://chat.us.freenode.net/rubyworks
41
+ extra: {}
42
+ load_path:
43
+ - lib
44
+ revision: 0
45
+ created: '2011-07-13'
46
+ summary: Edited Pictures for Ruby
47
+ title: PIC
48
+ name: pic
49
+ description: ! 'PIC is a pattern matching library, like regular expressions, based
50
+ on Cobol
51
+
52
+ edited pictures. It''s advantage over regular expressions is it more concise
53
+
54
+ syntax which geared specifically toward validation of user input.'
55
+ organization: rubyworks
56
+ version: 0.1.0
57
+ date: '2012-03-20'
@@ -0,0 +1,12 @@
1
+ # RELEASE HISTORY
2
+
3
+ ## 0.1.0 / 2012-03-20
4
+
5
+ This is the initial public release of PIC. PIC is still under development
6
+ and should be considered betaware, but it's API is stable and usable
7
+ enough to warrant a release.
8
+
9
+ Changes:
10
+
11
+ * Happy First Release Day!
12
+
@@ -0,0 +1,27 @@
1
+ PIC - Cobol Picture Pattern Matching
2
+
3
+ Copyright (c) 2011 Rubyworks. All rights reserved
4
+
5
+ Licensed (spdx) BSD-2-Clause
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are
8
+ permitted provided that the following conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice, this list of
11
+ conditions and the following disclaimer.
12
+
13
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
14
+ of conditions and the following disclaimer in the documentation and/or other materials
15
+ provided with the distribution.
16
+
17
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
18
+ BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ (http://rubyworks.github.com/pic)
@@ -0,0 +1,38 @@
1
+ # PIC
2
+
3
+ [Homepage](http://rubyworks.github.com/pic) /
4
+ [Report Issue](http://github.com/rubyworks/pic/issues) /
5
+ [Source Code](http://github.com/rubyworks/pic) /
6
+ [Mailing List](http://groups.google.com/rubyworks-mailinglist) /
7
+ [IRC Channel](http://chat.us.freenode.net/rubyworks)
8
+
9
+ [![Build Status](https://secure.travis-ci.org/rubyworks/pic.png)](http://travis-ci.org/rubyworks/pic)
10
+
11
+
12
+ ## Description
13
+
14
+ PIC is pattern matching system roughly based on Cobol Pictures. It serves
15
+ as an alternative to Regular Expressions for common data format needs.
16
+
17
+
18
+ ## Examples
19
+
20
+ PIC['Z.99'].to_re #=> /\d*\.\d\d/
21
+
22
+
23
+ ## Status
24
+
25
+ Currently PIC is very much in a state of "design development". It will take
26
+ some time to workout the best correlations between picture and regular
27
+ expression. Suggestions and patches welcome.
28
+
29
+
30
+ ## Reference Material
31
+
32
+ * [Edited Pictures](http://www.csis.ul.ie/cobol/course/EditedPics.htm)
33
+
34
+
35
+ ## Copyright & License
36
+
37
+ Copyright (c) 2011 Trans, Rubyworks
38
+
@@ -0,0 +1,76 @@
1
+ module PIC
2
+
3
+ #
4
+ def self.[](pic)
5
+ Template.new(pic)
6
+ end
7
+
8
+ #
9
+ class Template
10
+
11
+ #
12
+ def initialize(pic)
13
+ @pic = pic
14
+ end
15
+
16
+ #
17
+ attr :pic
18
+
19
+ #
20
+ def to_re
21
+ re = ''
22
+ pic.scan(SCAN) do |s,c|
23
+ re << remap(s) + recnt(c)
24
+ end
25
+ Regexp.new(re)
26
+ end
27
+
28
+ #
29
+ alias_method :to_regexp, :to_re
30
+
31
+ #
32
+ def =~(string)
33
+ to_re =~ string
34
+ end
35
+
36
+ private
37
+
38
+ #
39
+ def remap(s)
40
+ REMAP[s] || raise(ArgumentError) #('\' + s)
41
+ end
42
+
43
+ #
44
+ def recnt(c)
45
+ return '' unless c
46
+
47
+ case c
48
+ when /\[(\d+)\.\.(\d+)\]/
49
+ '{'+$1+','+$2+'}'
50
+ when /\[(\d+)\,(\d+)\]/
51
+ '{'+$1+','+$2+'}'
52
+ when /\[(\d+)\]/
53
+ '{'+$1+'}'
54
+ end
55
+ end
56
+
57
+ #
58
+ SCAN = /(\S)(\[.*?\])?/
59
+
60
+ #
61
+ REMAP = {
62
+ 'X' => '.',
63
+ '9' => '\d',
64
+ 'Z' => '\d*',
65
+ '0' => '\d',
66
+ 'A' => '[A-Za-z]',
67
+ 'W' => '\w',
68
+ '.' => '\.',
69
+ ',' => '\,',
70
+ '-' => '\-',
71
+ '/' => '\/'
72
+ }
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,27 @@
1
+ # Ruby Data Pictures
2
+
3
+ require 'pic'
4
+
5
+ ## Basic Regexp Conversions
6
+
7
+ PIC['X'].to_re #=> /./
8
+ PIC['A'].to_re #=> /[A-Za-z]/
9
+ PIC['W'].to_re #=> /\w/
10
+ PIC['9'].to_re #=> /\d/
11
+ PIC['Z'].to_re #=> /\d*/
12
+
13
+ PIC['.'].to_re #=> /\./
14
+ PIC[','].to_re #=> /\,/
15
+ PIC['-'].to_re #=> /\-/
16
+ PIC['/'].to_re #=> /\//
17
+
18
+ ## General Conversions
19
+
20
+ PIC['XX'].to_re #=> /../
21
+ PIC['AA'].to_re #=> /[A-Za-z][A-Za-z]/
22
+ PIC['WW'].to_re #=> /\w\w/
23
+
24
+ ## Advanced Conversions
25
+
26
+
27
+
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Sawyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: qed
16
+ requirement: &20633340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *20633340
25
+ - !ruby/object:Gem::Dependency
26
+ name: ae
27
+ requirement: &20632160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *20632160
36
+ - !ruby/object:Gem::Dependency
37
+ name: detroit
38
+ requirement: &20630840 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *20630840
47
+ - !ruby/object:Gem::Dependency
48
+ name: reap
49
+ requirement: &20629580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *20629580
58
+ description: ! 'PIC is a pattern matching library, like regular expressions, based
59
+ on Cobol
60
+
61
+ edited pictures. It''s advantage over regular expressions is it more concise
62
+
63
+ syntax which geared specifically toward validation of user input.'
64
+ email:
65
+ - transfire@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files:
69
+ - LICENSE.txt
70
+ - HISTORY.md
71
+ - README.md
72
+ files:
73
+ - .ruby
74
+ - lib/pic.rb
75
+ - spec/pic.md
76
+ - LICENSE.txt
77
+ - HISTORY.md
78
+ - README.md
79
+ homepage: http://rubyworks.github.com/pic
80
+ licenses:
81
+ - BSD-2-Clause
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.11
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Edited Pictures for Ruby
104
+ test_files: []