scrutiny 0.0.1
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 +64 -0
- data/Rakefile +44 -0
- data/lib/scrutiny.rb +63 -0
- metadata +56 -0
data/README.textile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
h2. Introduction
|
2
|
+
|
3
|
+
Given a string of text, scrutiny adds the ability to ask questions about the format of the string in a more readable way.
|
4
|
+
To get started,
|
5
|
+
|
6
|
+
bq. @gem install scrutiny@
|
7
|
+
|
8
|
+
Then require the gem:
|
9
|
+
|
10
|
+
bq. @require 'scrutiny'@
|
11
|
+
|
12
|
+
This will make several methods available on the String class:
|
13
|
+
* @words@
|
14
|
+
* @sentences@
|
15
|
+
* @has_at_least@
|
16
|
+
* @has_at_most@
|
17
|
+
* @has_something@
|
18
|
+
* @each_word@
|
19
|
+
* @each_sentence@
|
20
|
+
|
21
|
+
Perhaps the simplest example is something like:
|
22
|
+
|
23
|
+
bq. @"How many words are here?".words => ["How", "many", "words", "are", "here"]@
|
24
|
+
|
25
|
+
Similarly, you can parse the sentences as well:
|
26
|
+
|
27
|
+
bq. @"Hello. How are you?".sentences => ["Hello.", "How are you?"]@
|
28
|
+
|
29
|
+
|
30
|
+
You can also use the @has_at_least@ and @has_at_most@ methods to check if a string fits within some constraints.
|
31
|
+
|
32
|
+
bq. @"This sentence is too short.".has_at_least(8.words) => false@
|
33
|
+
|
34
|
+
bq. @"This sentence is much too long.".has_at_most(1.word) => false@
|
35
|
+
|
36
|
+
bq. @"Perhaps I need to write more here.".has_at_least(5.sentences) => false@
|
37
|
+
|
38
|
+
bq. @"This sentence is just right.".has_at_least(1.sentence) => true@
|
39
|
+
|
40
|
+
|
41
|
+
h2. LICENSE:
|
42
|
+
|
43
|
+
(The MIT License)
|
44
|
+
|
45
|
+
Copyright (c) 2011
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
+
a copy of this software and associated documentation files (the
|
49
|
+
'Software'), to deal in the Software without restriction, including
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
53
|
+
the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be
|
56
|
+
included in all copies or substantial portions of the Software.
|
57
|
+
|
58
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/package_task'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
GEM = "scrutiny"
|
6
|
+
GEM_VERSION = "0.0.1"
|
7
|
+
SUMMARY = "Adds methods to String and Integer to check constraints on written text."
|
8
|
+
AUTHOR = "Jared Stilwell"
|
9
|
+
EMAIL = "jared.k.stilwell@gmail.com"
|
10
|
+
HOMEPAGE = "http://uprightnetizen.com/scrutiny-gem"
|
11
|
+
|
12
|
+
spec = Gem::Specification.new do |s|
|
13
|
+
s.name = GEM
|
14
|
+
s.version = GEM_VERSION
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.summary = SUMMARY
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
s.files = FileList['app_generators/**/*', 'bin/*', 'lib/**/*.rb', '[A-Z]*'].to_a
|
19
|
+
|
20
|
+
s.author = AUTHOR
|
21
|
+
s.email = EMAIL
|
22
|
+
s.homepage = HOMEPAGE
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
26
|
+
t.pattern = FileList['spec/**/*_spec.rb']
|
27
|
+
t.rspec_opts = %w(-fs --color)
|
28
|
+
end
|
29
|
+
|
30
|
+
Gem::PackageTask.new(spec) do |pkg|
|
31
|
+
pkg.gem_spec = spec
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Install the gem locally"
|
35
|
+
task :install => [:package] do
|
36
|
+
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Create a gemspec file"
|
40
|
+
task :make_spec do
|
41
|
+
File.open("#{GEM}.gemspec", "w") do |file|
|
42
|
+
file.puts spec.to_ruby
|
43
|
+
end
|
44
|
+
end
|
data/lib/scrutiny.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
class String
|
2
|
+
def words
|
3
|
+
self.scan(/[\w\'\"\-\_\$\#\@\^\&\*\(\)\~\[\]\{\}\<\>\/]+/)
|
4
|
+
end
|
5
|
+
|
6
|
+
def sentences
|
7
|
+
self.scan(/[\w\'\"\-\_\$\#\@\^\&\*\(\)\~\[\]\{\}\<\>\/][^\.\?\!]*[\.\?\!]/)
|
8
|
+
end
|
9
|
+
|
10
|
+
def has_at_least(matcher)
|
11
|
+
constraint = matcher.call(self)
|
12
|
+
constraint[:matches].count >= constraint[:limit]
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_at_most(matcher)
|
16
|
+
constraint = matcher.call(self)
|
17
|
+
constraint[:matches].count <= constraint[:limit]
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_something_like(regexp)
|
21
|
+
self.scan(regexp).count > 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def each_word(action, regexp)
|
25
|
+
result = true
|
26
|
+
self.words.each do |word|
|
27
|
+
result = word.method(action).call(regexp) && result
|
28
|
+
end
|
29
|
+
|
30
|
+
result
|
31
|
+
end
|
32
|
+
|
33
|
+
def each_sentence(action, matcher)
|
34
|
+
result = true
|
35
|
+
self.sentences.each do |sentence|
|
36
|
+
result = sentence.method(action).call(matcher) && result
|
37
|
+
end
|
38
|
+
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Integer
|
44
|
+
def word
|
45
|
+
self.words
|
46
|
+
end
|
47
|
+
|
48
|
+
def words
|
49
|
+
Proc.new do |string|
|
50
|
+
{:limit => self, :matches => string.words}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sentence
|
55
|
+
self.sentences
|
56
|
+
end
|
57
|
+
|
58
|
+
def sentences
|
59
|
+
Proc.new do |string|
|
60
|
+
{:limit => self, :matches => string.sentences}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scrutiny
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jared Stilwell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-14 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: jared.k.stilwell@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/scrutiny.rb
|
26
|
+
- README.textile
|
27
|
+
- Rakefile
|
28
|
+
homepage: http://uprightnetizen.com/scrutiny-gem
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Adds methods to String and Integer to check constraints on written text.
|
55
|
+
test_files: []
|
56
|
+
|