word_up 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ *.swp
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in word_up.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Dru
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # WordUp
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'word_up'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install word_up
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module WordUp
2
+ VERSION = "0.0.1"
3
+ end
data/lib/word_up.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'word_up/version'
2
+
3
+ class String
4
+ def word_distance(w1, w2)
5
+ sentence = self.gsub(/[^0-9a-z ]/i, '').split
6
+ w1_index = sentence.index(w1.gsub(/[^0-9a-z ]/i, ''))
7
+ w2_index = sentence.index(w2.gsub(/[^0-9a-z ]/i, ''))
8
+ ((w1_index - w2_index).abs - 1 )
9
+ end
10
+
11
+ def word_after(w)
12
+ sentence = self.gsub(/[^0-9a-z ]/i, '').split
13
+ param_index = sentence.index(w)
14
+ sentence[param_index + 1]
15
+ end
16
+
17
+ def capitalized?
18
+ self.capitalize == self
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ require_relative '../lib/word_up'
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe WordUp do
4
+ before :each do
5
+ @sentence1 = "This is a sample sentence."
6
+ @sentence2 = "A long sentence with an apostrophe hasn't been tested yet."
7
+ end
8
+
9
+ describe "#word_distance" do
10
+ it "should return the distance between two words" do
11
+ @sentence1.word_distance("is", "sentence").should == 2
12
+ @sentence2.word_distance("hasn't", "yet").should == 2
13
+ end
14
+ end
15
+
16
+ describe "#word_after" do
17
+ context "when a word follows"
18
+ it "should return the word" do
19
+ @sentence1.word_after("is").should == "a"
20
+ end
21
+
22
+ context "when no word follows" do
23
+ it "should return nil" do
24
+ @sentence2.word_after("yet").should == nil
25
+ end
26
+ end
27
+ end
28
+
29
+ describe "#capitalized?" do
30
+ context "when a word is capitalized" do
31
+ it "should return true" do
32
+ "Sample".capitalized?.should == true
33
+ end
34
+ end
35
+
36
+ context "when a word is not capitalized" do
37
+ it "should return false" do
38
+ "sample".capitalized?.should == false
39
+ end
40
+ end
41
+ end
42
+ end
data/word_up.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/word_up/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dru Riley"]
6
+ gem.email = ["drurly@gmail.com"]
7
+ gem.description = %q{Language analysis tool}
8
+ gem.summary = %q{Word Up Gem}
9
+ gem.homepage = "https://github.com/DruRly/word_up"
10
+ gem.add_development_dependency "rspec"
11
+ gem.add_development_dependency "rake"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "word_up"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = WordUp::VERSION
19
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: word_up
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dru Riley
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70122958275900 !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: *70122958275900
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70122958275000 !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: *70122958275000
36
+ description: Language analysis tool
37
+ email:
38
+ - drurly@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - lib/word_up.rb
49
+ - lib/word_up/version.rb
50
+ - spec/spec_helper.rb
51
+ - spec/word_up_spec.rb
52
+ - word_up.gemspec
53
+ homepage: https://github.com/DruRly/word_up
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.15
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Word Up Gem
77
+ test_files:
78
+ - spec/spec_helper.rb
79
+ - spec/word_up_spec.rb