word_play 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/Gemfile ADDED
File without changes
File without changes
File without changes
@@ -0,0 +1,84 @@
1
+ # == word_play.rb
2
+ # This gem file contains the 'Word' class definition that
3
+ # tests if a given pair of words is an Anagram and if a
4
+ # given word is a palindrome!
5
+ #
6
+ # Word class. The *Word* class consists of methods that could be performed
7
+ # on strings, any number of methods can be added. This file consists of two methods
8
+ # named *is_anagram?* and *is_palindrome?*.
9
+ #
10
+ # == Summary
11
+ #
12
+ # This gem can be used to perform two types of tests on string:
13
+ # - Use _is_anagram?_ to check if two strigs are Anagram of each other
14
+ # - Use _is_palindrome?_ to check if a string is a Palindrome
15
+ #
16
+ # == Example
17
+ #
18
+ # word1 = Word.new("scream") # Initialize the class Word
19
+ # word2 = Word.new("creams") # Initialize the class Word
20
+ # is_anagram?(word1,word2) # Pass 2 words to check if they are Anagram
21
+ # is_palindrome("Madam") # Check if a word is palindrome
22
+ #
23
+ # === Anagram definition:
24
+ #
25
+ # A word or phraseis said to be an Anagram if rearranging the exact letters would
26
+ # produce another word. Example: scream and creams
27
+ #
28
+ # === Palindrome definition
29
+ #
30
+ # A word or phrase is said to be a Palindrome, if we obtain the same word when
31
+ # read from the reverse. Example: "A nut for a jar of tuna"
32
+ #
33
+ # == Reference
34
+ #
35
+ # - http://en.wikipedia.org/wiki/Palindrome
36
+ # - http://en.wikipedia.org/wiki/Anagram
37
+ #
38
+ # == Contact
39
+ #
40
+ # Author:: Anupama Iyengar (mailto:sadicarnot@gmail.com)
41
+ # Website:: ''
42
+ # Date:: Sunday November 17, 2013
43
+
44
+ class Word
45
+ class << self
46
+
47
+ # In order to check for \*Anagram* convert all the letters
48
+ # into lowercase, split them into letters, sort them and
49
+ # join them to form a string!
50
+ def process(text)
51
+ text.downcase.split('').sort.join
52
+ end
53
+
54
+ # Return \_true_ if the two entered strings are Anagram, else
55
+ # return \_false_
56
+ def is_anagram?(text1,text2)
57
+ if (process(text1) == process(text2))
58
+ puts " The 2 words are anagram of each other"
59
+ return true
60
+ else
61
+ puts " The 2 words are not anagrams"
62
+ return false
63
+ end
64
+ end
65
+
66
+ # Return \_true_ if the entered string is a \*Palindrome*, else
67
+ # return \_false_
68
+ def is_palindrome?(text)
69
+
70
+ if (text.downcase == text.downcase.reverse)
71
+ puts " The word is a palindrome"
72
+ return true
73
+ else
74
+ puts " The words is not a palindrome"
75
+ return false
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
82
+
83
+
84
+
@@ -0,0 +1,3 @@
1
+ module WordPlay
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ require 'word_play'
@@ -0,0 +1,44 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Word do
4
+
5
+ context 'Palindrome' do
6
+ let(:data) { [ "mAdam", "taat" ] }
7
+ it "works" do
8
+ data.each do |word|
9
+
10
+ Word.is_palindrome?(word).should be_true
11
+
12
+ end
13
+ end
14
+ end
15
+
16
+ context 'Palindrome' do
17
+ let(:data) { [ "mAderam", "twoaat" ] }
18
+ it "works" do
19
+ data.each do |word|
20
+
21
+ Word.is_palindrome?(word).should be_false
22
+
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+ context 'Anagrams' do
29
+ word1 = Word.new("madam")
30
+ word2 = Word.new("damam")
31
+ it "works" do
32
+ Word.is_anagram?(word1,word2).should be_true
33
+ end
34
+ end
35
+
36
+ context 'Anagrams' do
37
+ word1 = Word.new("madam")
38
+ word2 = Word.new("dreamam")
39
+ it "works" do
40
+ Word.is_anagram?(word1,word2).should be_false
41
+ end
42
+ end
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: word_play
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anupama Iyengar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! ' anagrams and palindrome'
79
+ email:
80
+ - sadicarnot@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - README.md
86
+ - Gemfile
87
+ - Rakefile
88
+ - spec/word_play_spec.rb
89
+ - spec/spec_helper.rb
90
+ - lib/word_play/version.rb
91
+ - lib/word_play.rb
92
+ homepage: ''
93
+ licenses: []
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.24
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: methods to find anagrams and palindromes
116
+ test_files:
117
+ - spec/word_play_spec.rb
118
+ - spec/spec_helper.rb