scrutiny 0.0.1 → 0.0.2
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/README.textile +40 -10
- data/Rakefile +2 -2
- data/lib/scrutiny.rb +46 -9
- metadata +3 -3
data/README.textile
CHANGED
@@ -9,33 +9,63 @@ Then require the gem:
|
|
9
9
|
|
10
10
|
bq. @require 'scrutiny'@
|
11
11
|
|
12
|
-
|
12
|
+
Then call the @scrutinize@ method on a String object:
|
13
|
+
|
14
|
+
bq. @my_new_string = "Hello Scrutiny!".scrutinize@
|
15
|
+
|
16
|
+
This attaches several methods to the object:
|
17
|
+
* @letters@
|
13
18
|
* @words@
|
14
19
|
* @sentences@
|
15
20
|
* @has_at_least@
|
16
21
|
* @has_at_most@
|
17
|
-
* @
|
22
|
+
* @has_exactly@
|
23
|
+
* @has_something_like@
|
24
|
+
* @each_letter@
|
18
25
|
* @each_word@
|
19
26
|
* @each_sentence@
|
20
27
|
|
21
|
-
|
28
|
+
You can now parse the string into its component words...
|
29
|
+
|
30
|
+
bq. @my_new_string.words => ["Hello", "Scrutiny"]@
|
31
|
+
|
32
|
+
and check the constraints of the string...
|
33
|
+
|
34
|
+
bq. @my_new_string.has_at_least 2.words # => true@
|
35
|
+
|
36
|
+
as well as check constraints on a smaller scope.
|
22
37
|
|
23
|
-
bq. @
|
38
|
+
bq. @my_new_string.each_word :has_at_least, 10.letters # => false@
|
24
39
|
|
25
|
-
Similarly, you can parse the sentences as well:
|
26
40
|
|
27
|
-
|
41
|
+
The same semantics apply to sentences as well.
|
28
42
|
|
43
|
+
@"Hello. How are you?".scrutinize.sentences => ["Hello.", "How are you?"]@
|
29
44
|
|
30
45
|
You can also use the @has_at_least@ and @has_at_most@ methods to check if a string fits within some constraints.
|
31
46
|
|
32
|
-
bq. @"
|
47
|
+
bq. @my_masterpiece = "Hi. My name is Joe. I work in a button factory.".scrutinize@
|
48
|
+
|
49
|
+
bq. @my_masterpiece.has_at_least 3.sentences # => true@
|
50
|
+
|
51
|
+
bq. @my_masterpiece.has_at_most 2.sentences # => false@
|
52
|
+
|
53
|
+
bq. @my_masterpiece.words.inject(:+) # => "HelloMynameisJoeIworkinabuttonfactory"@
|
54
|
+
|
55
|
+
h2. Release Notes
|
56
|
+
|
57
|
+
h3. 0.0.2
|
58
|
+
* Added support for per-letter constraints.
|
59
|
+
* Added the @each_letter()@ method; Returns @true@ if the constraint holds for each letter, @false@ otherwise.
|
60
|
+
* Added the @has_exactly()@ method; Returns @true@ if the constraint matches exactly, @false@ otherwise.
|
61
|
+
* Moved business methods into a module. String are now prepared with the @scrutinize()@ method.
|
33
62
|
|
34
|
-
|
63
|
+
h3. 0.0.1
|
64
|
+
* First release of anything meaningful.
|
35
65
|
|
36
|
-
|
66
|
+
h2. Thanks
|
37
67
|
|
38
|
-
|
68
|
+
Thank you for spending the cycles to read this.
|
39
69
|
|
40
70
|
|
41
71
|
h2. LICENSE:
|
data/Rakefile
CHANGED
@@ -3,8 +3,8 @@ require 'rubygems/package_task'
|
|
3
3
|
require 'rspec/core/rake_task'
|
4
4
|
|
5
5
|
GEM = "scrutiny"
|
6
|
-
GEM_VERSION = "0.0.
|
7
|
-
SUMMARY = "
|
6
|
+
GEM_VERSION = "0.0.2"
|
7
|
+
SUMMARY = "Helper methods for analyzing written words in strings."
|
8
8
|
AUTHOR = "Jared Stilwell"
|
9
9
|
EMAIL = "jared.k.stilwell@gmail.com"
|
10
10
|
HOMEPAGE = "http://uprightnetizen.com/scrutiny-gem"
|
data/lib/scrutiny.rb
CHANGED
@@ -1,46 +1,83 @@
|
|
1
|
-
|
1
|
+
module Scrutiny
|
2
|
+
def letters
|
3
|
+
self.scan(/[A-Za-z]/)
|
4
|
+
end
|
5
|
+
|
2
6
|
def words
|
3
7
|
self.scan(/[\w\'\"\-\_\$\#\@\^\&\*\(\)\~\[\]\{\}\<\>\/]+/)
|
4
8
|
end
|
5
|
-
|
9
|
+
|
6
10
|
def sentences
|
7
11
|
self.scan(/[\w\'\"\-\_\$\#\@\^\&\*\(\)\~\[\]\{\}\<\>\/][^\.\?\!]*[\.\?\!]/)
|
8
12
|
end
|
9
|
-
|
13
|
+
|
10
14
|
def has_at_least(matcher)
|
11
15
|
constraint = matcher.call(self)
|
12
16
|
constraint[:matches].count >= constraint[:limit]
|
13
17
|
end
|
14
|
-
|
18
|
+
|
15
19
|
def has_at_most(matcher)
|
16
20
|
constraint = matcher.call(self)
|
17
21
|
constraint[:matches].count <= constraint[:limit]
|
18
22
|
end
|
19
23
|
|
24
|
+
def has_exactly(matcher)
|
25
|
+
constraint = matcher.call(self)
|
26
|
+
constraint[:matches].count == constraint[:limit]
|
27
|
+
end
|
28
|
+
|
20
29
|
def has_something_like(regexp)
|
21
30
|
self.scan(regexp).count > 0
|
22
31
|
end
|
23
32
|
|
24
|
-
def
|
33
|
+
def each_letter(action, matcher)
|
34
|
+
result = true
|
35
|
+
self.letters.each do |letter|
|
36
|
+
letter.scrutinize
|
37
|
+
result = letter.method(action).call(matcher) && result
|
38
|
+
end
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
def each_word(action, matcher)
|
25
43
|
result = true
|
26
44
|
self.words.each do |word|
|
27
|
-
|
45
|
+
word.scrutinize
|
46
|
+
result = word.method(action).call(matcher) && result
|
28
47
|
end
|
29
|
-
|
30
48
|
result
|
31
49
|
end
|
32
|
-
|
50
|
+
|
33
51
|
def each_sentence(action, matcher)
|
34
52
|
result = true
|
35
53
|
self.sentences.each do |sentence|
|
54
|
+
sentence.scrutinize
|
36
55
|
result = sentence.method(action).call(matcher) && result
|
37
56
|
end
|
38
|
-
|
39
57
|
result
|
40
58
|
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class String
|
62
|
+
def scrutinize
|
63
|
+
class << self
|
64
|
+
include Scrutiny
|
65
|
+
end
|
66
|
+
self
|
67
|
+
end
|
41
68
|
end
|
42
69
|
|
43
70
|
class Integer
|
71
|
+
def letter
|
72
|
+
self.letters
|
73
|
+
end
|
74
|
+
|
75
|
+
def letters
|
76
|
+
Proc.new do |string|
|
77
|
+
{:limit => self, :matches => string.letters}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
44
81
|
def word
|
45
82
|
self.words
|
46
83
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: scrutiny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jared Stilwell
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-15 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description:
|
@@ -51,6 +51,6 @@ rubyforge_project:
|
|
51
51
|
rubygems_version: 1.8.5
|
52
52
|
signing_key:
|
53
53
|
specification_version: 3
|
54
|
-
summary:
|
54
|
+
summary: Helper methods for analyzing written words in strings.
|
55
55
|
test_files: []
|
56
56
|
|