strmask 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby ADDED
@@ -0,0 +1,43 @@
1
+ ---
2
+ source:
3
+ - meta
4
+ authors:
5
+ - name: Thomas Sawyer
6
+ email: transfire@gmail.com
7
+ copyrights:
8
+ - holder: Thomas Sawyer
9
+ year: '2009'
10
+ license: BSD-2-Clause
11
+ replacements: []
12
+ alternatives: []
13
+ requirements:
14
+ - name: qed
15
+ groups:
16
+ - test
17
+ development: true
18
+ - name: detroit
19
+ groups:
20
+ - build
21
+ development: true
22
+ dependencies: []
23
+ conflicts: []
24
+ repositories: []
25
+ resources:
26
+ Homepage: http://rubyworks.github.com/strmask
27
+ Source Code: http://github.com/rubyworks/strmask
28
+ Mailing List: http://groups.google.com/group/rubyworks-mailinglist
29
+ extra: {}
30
+ load_path:
31
+ - lib
32
+ revision: 0
33
+ created: '2009-07-19'
34
+ summary: String Algebra
35
+ title: String::Mask
36
+ version: 0.3.2
37
+ name: strmask
38
+ description: ! 'String::Mask provides a kind-of string algebra useful for manipulating
39
+ strings
40
+
41
+ in comparitive ways, eg. add, subtract, xor, etc.'
42
+ organization: RubyWorks
43
+ date: '2011-10-27'
@@ -0,0 +1,9 @@
1
+ --title "StrMask"
2
+ --readme README.rdoc
3
+ --output-dir doc
4
+ --protected
5
+ --private
6
+ lib/**/*.rb
7
+ -
8
+ [A-Z]*.*
9
+
@@ -1,4 +1,16 @@
1
- = HISTORY
1
+ = RELEASE HISTORY
2
+
3
+ == 0.3.2 / 2011-10-27
4
+
5
+ Fixed bug that prevented plain strings from being coerced
6
+ into masks. This release also brings the build system up
7
+ to date with latest tools. (Note: 0.3.1 was botched).
8
+
9
+ Changes:
10
+
11
+ * Fixed issue with plain strings not being coerced.
12
+ * Modernize build configuration.
13
+
2
14
 
3
15
  == 0.3.0 / 2010-04-18
4
16
 
@@ -0,0 +1,31 @@
1
+ = COPYRIGHT NOTICES
2
+
3
+ == String Mask
4
+
5
+ Copyright:: (c) 2009 Thomas Sawyer, Rubyworks
6
+ License:: BSD-2-Clause
7
+ Website:: http://rubyworks.github.com/strmask
8
+
9
+ Copyright 2009 Thomas Sawyer. All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice,
15
+ this list of conditions and the following disclaimer.
16
+
17
+ 2. Redistributions in binary form must reproduce the above copyright
18
+ notice, this list of conditions and the following disclaimer in the
19
+ documentation and/or other materials provided with the distribution.
20
+
21
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
+ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+
@@ -0,0 +1,62 @@
1
+ = String Masking
2
+
3
+ require 'strmask'
4
+
5
+ There are a few ways to create a string mask.
6
+
7
+ x1 = String::Mask.new("abc..123", '.')
8
+ x2 = String::Mask["abc..123", '.']
9
+ x3 = "abc..123".mask('.')
10
+
11
+ All of the above examples are equivelent.
12
+
13
+ x1.assert == x2
14
+ x2.assert == x3
15
+ x3.assert == x1
16
+
17
+ Notice in all these example we specified a dot ('.') as the escaping
18
+ character. Leaving this off defaults the chracter to ASCII ESC ("\032").
19
+ ASCII ESC is a good choice for real world usage, but for demonstration
20
+ puposes a dot is clearly much easier to read.
21
+
22
+ We will use the folowing two string masks to demonstrate the various masking
23
+ operators below.
24
+
25
+ x1 = "abc..123".mask('.')
26
+ x2 = "ab..789.".mask('.')
27
+
28
+ For Addition, as long as there is a value other then empty slot the character
29
+ filters though, with the last string taking precedence.
30
+
31
+ (x1 + x2) #=> "abc.7893".mask('.')
32
+ (x2 + x1) #=> "abc.7123".mask('.')
33
+
34
+ The OR operator is the same as addition.
35
+
36
+ (x1 | x2) #=> "abc.7893".mask('.')
37
+ (x2 | x1) #=> "abc.7123".mask('.')
38
+
39
+ For Subtraction, where the characters are the same, the result is empty, where
40
+ they differ the result reflects the last string.
41
+
42
+ (x1 - x2) #=> "....789.".mask('.')
43
+ (x2 - x1) #=> "..c..123".mask('.')
44
+
45
+ For Multiplication (Exclusive AND), where the characters are the same the
46
+ result is the same, where they differ the result reflects the later.
47
+
48
+ (x1 * x2) #=> "ab..789.".mask('.')
49
+ (x2 * x1) #=> "abc..123".mask('.')
50
+
51
+ The AND operator, only slots that are the same (using ==) filter through.
52
+
53
+ (x1 & x2) #=> "ab......".mask('.')
54
+ (x2 & x1) #=> "ab......".mask('.')
55
+
56
+ The XOR operator, only where there is an empty slot will the value filter
57
+ through.
58
+
59
+ (x1 ^ x2) #=> "..c.7..3".mask('.')
60
+ (x2 ^ x1) #=> "..c.7..3".mask('.')
61
+
62
+
@@ -1,7 +1,9 @@
1
1
  = String::Mask
2
2
 
3
- * home: http://rubyworks.github.com/strmask
4
- * work: http://github.com/rubyworks/strmask
3
+ {Homepage}[http://rubyworks.github.com/strmask] |
4
+ {Source Code}[http://github.com/rubyworks/strmask]
5
+
6
+ {<img src="http://travis-ci.org/rubyworks/strmask.png" />}[http://travis-ci.org/rubyworks/strmask]
5
7
 
6
8
 
7
9
  == DESCRIPTION
@@ -10,6 +12,7 @@ Mask provides a string utility to manipulate strings
10
12
  in logicomathematical manner, ie. add, subtract, xor,
11
13
  etc.
12
14
 
15
+
13
16
  == SYNOPSIS
14
17
 
15
18
  Mask objects can be created explicitly via #new.
@@ -30,18 +33,18 @@ it repesents another mask akin to the first.
30
33
  "abc..123".mask('.') + "ab..789." #=> "abc.7893"
31
34
 
32
35
 
33
- == HOW TO INSTALL
36
+ == INSTALL
34
37
 
35
38
  To install with RubyGems simply open a console and type:
36
39
 
37
- gem install mask
40
+ $ gem install strmask
38
41
 
39
42
 
40
- == COPYRIGHT
43
+ == COPYRIGHTS
41
44
 
42
- Copyright (c) 2009 Thomas Sawyer
45
+ Copyright (c) 2009 Thomas Sawyer, Rubyworks
43
46
 
44
- This program is ditributed unser the terms of the LGPL license.
47
+ This program is ditributed unser the terms of the *FreeBSD* license.
45
48
 
46
- See the LICENSE or COPYING file for details.
49
+ See the NOTICE.rdoc file for details.
47
50
 
@@ -9,31 +9,43 @@ class String
9
9
 
10
10
  # = Mask
11
11
  #
12
+ #--
13
+ # TODO: Probably need to create a proper #hash method.
14
+ #++
12
15
  class Mask
13
16
 
17
+ # Current version.
18
+ VERSION = "0.3.2" # :erb: VERSION = "<%= version %>"
19
+
20
+ # Substitue (TODO: rename)
14
21
  ESC = "\032" # ASCII SUBSTITUTE
15
22
 
23
+ # New Mask.
24
+ #
25
+ # @param [String] string
26
+ # Any regular or masked string.
27
+ #
28
+ # @param [String] re
29
+ # Single character string used to mark empty slots.
30
+ #
16
31
  def self.[](string, re=nil)
17
32
  new(string, re)
18
33
  end
19
34
 
20
- private
21
-
35
+ # Initialize new string mask.
36
+ #
37
+ # @param [String] string
38
+ # Any regular or masked string.
39
+ #
40
+ # @param [String] re
41
+ # Single character string used to mark empty slots.
42
+ #
22
43
  def initialize(string, re=nil)
23
44
  @to_str = string.dup
24
45
  @re = re
25
46
  mask!(re) if re
26
47
  end
27
48
 
28
- def convert(other)
29
- case other
30
- when Mask
31
- other
32
- else
33
- self.class.new(other.to_s, re)
34
- end
35
- end
36
-
37
49
  public
38
50
 
39
51
  # The underlying string object.
@@ -56,10 +68,17 @@ class String
56
68
  to_str[*a]
57
69
  end
58
70
 
71
+ # Create a new mask with the same underlying string, but
72
+ # using a different empty slot.
73
+ #
74
+ # @param [String] re
75
+ # Single character string used to mark empty slots.
76
+ #
59
77
  def mask(re)
60
78
  self.class.new(to_str,re)
61
79
  end
62
80
 
81
+ #
63
82
  def mask!(re)
64
83
  to_str.gsub!(re){ |s| ESC * s.size }
65
84
  end
@@ -226,6 +245,11 @@ class String
226
245
  # end
227
246
  #end
228
247
 
248
+ #
249
+ #def coerce(other)
250
+ # [self, other.mask(@re)]
251
+ #end
252
+
229
253
  # Delegate any missing methods to underlying string.
230
254
  #
231
255
  def method_missing(s, *a, &b)
@@ -236,6 +260,17 @@ class String
236
260
  end
237
261
  end
238
262
 
263
+ private
264
+
265
+ def convert(other)
266
+ case other
267
+ when Mask
268
+ other
269
+ else
270
+ self.class.new(other.to_s, @re)
271
+ end
272
+ end
273
+
239
274
  end
240
275
 
241
276
  end
@@ -0,0 +1,43 @@
1
+ ---
2
+ source:
3
+ - meta
4
+ authors:
5
+ - name: Thomas Sawyer
6
+ email: transfire@gmail.com
7
+ copyrights:
8
+ - holder: Thomas Sawyer
9
+ year: '2009'
10
+ license: BSD-2-Clause
11
+ replacements: []
12
+ alternatives: []
13
+ requirements:
14
+ - name: qed
15
+ groups:
16
+ - test
17
+ development: true
18
+ - name: detroit
19
+ groups:
20
+ - build
21
+ development: true
22
+ dependencies: []
23
+ conflicts: []
24
+ repositories: []
25
+ resources:
26
+ Homepage: http://rubyworks.github.com/strmask
27
+ Source Code: http://github.com/rubyworks/strmask
28
+ Mailing List: http://groups.google.com/group/rubyworks-mailinglist
29
+ extra: {}
30
+ load_path:
31
+ - lib
32
+ revision: 0
33
+ created: '2009-07-19'
34
+ summary: String Algebra
35
+ title: String::Mask
36
+ version: 0.3.2
37
+ name: strmask
38
+ description: ! 'String::Mask provides a kind-of string algebra useful for manipulating
39
+ strings
40
+
41
+ in comparitive ways, eg. add, subtract, xor, etc.'
42
+ organization: RubyWorks
43
+ date: '2011-10-27'
@@ -0,0 +1,61 @@
1
+ = String Masking
2
+
3
+ require 'strmask'
4
+
5
+ There are a few ways to create a string mask.
6
+
7
+ x1 = String::Mask.new("abc..123", '.')
8
+ x2 = String::Mask["abc..123", '.']
9
+ x3 = "abc..123".mask('.')
10
+
11
+ All of the above examples are equivelent.
12
+
13
+ x1.assert == x2
14
+ x2.assert == x3
15
+ x3.assert == x1
16
+
17
+ Notice in all these example we specified a dot ('.') as the escaping
18
+ character. Leaving this off defaults the chracter to ASCII ESC ("\032").
19
+ ASCII ESC is a good choice for real world usage, but for demonstration
20
+ puposes a dot is clearly much easier to read.
21
+
22
+ We will use the folowing two string masks to demonstrate the various masking
23
+ operators below.
24
+
25
+ x1 = "abc..123".mask('.')
26
+ x2 = "ab..789.".mask('.')
27
+
28
+ For Addition, as long as there is a value other then empty slot the character
29
+ filters though, with the last string taking precedence.
30
+
31
+ (x1 + x2) #=> "abc.7893".mask('.')
32
+ (x2 + x1) #=> "abc.7123".mask('.')
33
+
34
+ The OR operator is the same as addition.
35
+
36
+ (x1 | x2) #=> "abc.7893".mask('.')
37
+ (x2 | x1) #=> "abc.7123".mask('.')
38
+
39
+ For Subtraction, where the characters are the same, the result is empty, where
40
+ they differ the result reflects the last string.
41
+
42
+ (x1 - x2) #=> "....789.".mask('.')
43
+ (x2 - x1) #=> "..c..123".mask('.')
44
+
45
+ For Multiplication (Exclusive AND), where the characters are the same the
46
+ result is the same, where they differ the result reflects the later.
47
+
48
+ (x1 * x2) #=> "ab..789.".mask('.')
49
+ (x2 * x1) #=> "abc..123".mask('.')
50
+
51
+ The AND operator, only slots that are the same (using ==) filter through.
52
+
53
+ (x1 & x2) #=> "ab......".mask('.')
54
+ (x2 & x1) #=> "ab......".mask('.')
55
+
56
+ The XOR operator, only where there is an empty slot will the value filter
57
+ through.
58
+
59
+ (x1 ^ x2) #=> "..c.7..3".mask('.')
60
+ (x2 ^ x1) #=> "..c.7..3".mask('.')
61
+
metadata CHANGED
@@ -1,82 +1,85 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: strmask
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 0
9
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Thomas Sawyer
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
12
+ date: 2011-10-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: qed
16
+ requirement: &28079740 !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: *28079740
25
+ - !ruby/object:Gem::Dependency
26
+ name: detroit
27
+ requirement: &28078940 !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: *28078940
36
+ description: ! 'String::Mask provides a kind-of string algebra useful for manipulating
37
+ strings
16
38
 
17
- date: 2010-04-18 00:00:00 -04:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description: |-
22
- String::Mask provides a kind-of string algebra
23
- useful for manipulating strings in in comparitive
24
- ways, eg. add, subtract, xor, etc.
25
- email:
39
+ in comparitive ways, eg. add, subtract, xor, etc.'
40
+ email:
41
+ - transfire@gmail.com
26
42
  executables: []
27
-
28
43
  extensions: []
29
-
30
- extra_rdoc_files: []
31
-
32
- files:
44
+ extra_rdoc_files:
45
+ - HISTORY.rdoc
46
+ - README.rdoc
47
+ - QED.rdoc
48
+ - NOTICE.rdoc
49
+ files:
50
+ - .ruby
51
+ - .yardopts
33
52
  - lib/strmask.rb
34
- - meta/authors
35
- - meta/collection
36
- - meta/contact
37
- - meta/created
38
- - meta/description
39
- - meta/homepage
40
- - meta/license
41
- - meta/name
42
- - meta/released
43
- - meta/repository
44
- - meta/title
45
- - meta/version
53
+ - lib/strmask.yml
54
+ - qed/strmask.rdoc
46
55
  - test/test_strmask.rb
47
- - LICENSE
56
+ - HISTORY.rdoc
48
57
  - README.rdoc
49
- - HISTORY
50
- has_rdoc: true
51
- homepage: http://rubyworks.github.com/strmask
52
- licenses: []
53
-
58
+ - QED.rdoc
59
+ - NOTICE.rdoc
60
+ homepage:
61
+ licenses:
62
+ - BSD-2-Clause
54
63
  post_install_message:
55
- rdoc_options:
56
- - --title
57
- - String::Mask API
58
- require_paths:
64
+ rdoc_options: []
65
+ require_paths:
59
66
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- segments:
65
- - 0
66
- version: "0"
67
- required_rubygems_version: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- segments:
72
- - 0
73
- version: "0"
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
74
79
  requirements: []
75
-
76
- rubyforge_project: strmask
77
- rubygems_version: 1.3.6
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.10
78
82
  signing_key:
79
83
  specification_version: 3
80
- summary: String::Mask provides a kind-of string algebra
81
- test_files:
82
- - test/test_strmask.rb
84
+ summary: String Algebra
85
+ test_files: []
data/LICENSE DELETED
@@ -1,23 +0,0 @@
1
- The MIT License
2
-
3
- Copyright (c) 2009 Peter Vanbroekhoven & Thomas Sawyer
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
22
-
23
-
@@ -1 +0,0 @@
1
- Thomas Sawyer
@@ -1 +0,0 @@
1
- rubyworks
@@ -1 +0,0 @@
1
- rubyworks-mailinglist@googlegroups.com
@@ -1 +0,0 @@
1
- 2009-07-19
@@ -1,3 +0,0 @@
1
- String::Mask provides a kind-of string algebra
2
- useful for manipulating strings in in comparitive
3
- ways, eg. add, subtract, xor, etc.
@@ -1 +0,0 @@
1
- http://rubyworks.github.com/strmask
@@ -1 +0,0 @@
1
- MIT
data/meta/name DELETED
@@ -1 +0,0 @@
1
- strmask
@@ -1 +0,0 @@
1
- 2010-04-18
@@ -1 +0,0 @@
1
- git://github.com/rubyworks/strmask.git
data/meta/title DELETED
@@ -1 +0,0 @@
1
- String::Mask
@@ -1 +0,0 @@
1
- 0.3.0