d2w 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
1
+ module D2W
2
+ class FilterWordLengthWise
3
+ def filter_word_length_wise(exact_words, phone_no, dw_map)
4
+ length_3 = [];length_03 = [];length_04 = [];length_4 = [];length_5 = [];length_6 = [];length_7 = [];length_10 = []; length_05 = []
5
+ exact_words.each do |word|
6
+ if word.length == 3
7
+ length_3 << word if phone_no[0..2] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
8
+ end
9
+
10
+ if word.length == 3
11
+ length_03 << word if phone_no[3..5] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
12
+ end
13
+
14
+ if word.length == 4
15
+ length_4 << word if phone_no[0..3] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
16
+ end
17
+
18
+ if word.length == 4
19
+ length_04 << word if phone_no[6..9] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
20
+ end
21
+
22
+ if word.length == 5
23
+ length_5 << word if phone_no[0..4] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
24
+ end
25
+
26
+ if word.length == 5
27
+ length_05 << word if phone_no[5..9] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
28
+ end
29
+
30
+ if word.length == 6
31
+ length_6 << word if phone_no[4..9] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
32
+ end
33
+
34
+ if word.length == 7
35
+ length_7 << word if phone_no[3..9] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
36
+ end
37
+
38
+ if word.length == 10
39
+ length_10 << word if phone_no[0..9] == D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
40
+ end
41
+ end
42
+ words = [length_3, length_4, length_5, length_6, length_7, length_03, length_04, length_05, length_10]
43
+ D2W::WordCollection.new.word_collection(words)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ module D2W
2
+ # require 'thor'
3
+ class PhoneToWord
4
+ def digit2word(phone_no)
5
+
6
+ # path_of_dictionary = "/Users/babaloo/Downloads/dictionary.txt"
7
+
8
+ if phone_no.nil? || phone_no.length != 10 || phone_no.split('').select{|a|(a.to_i == 0 || a.to_i == 1)}.length > 0
9
+ return []
10
+ end
11
+ dw_map = {
12
+ "2" => ["a", "b", "c"],
13
+ "3" => ["d", "e", "f"],
14
+ "4" => ["g", "h", "i"],
15
+ "5" => ["j", "k", "l"],
16
+ "6" => ["m", "n", "o"],
17
+ "7" => ["p", "q", "r", "s"],
18
+ "8" => ["t", "u", "v"],
19
+ "9" => ["w", "x", "y", "z"]
20
+ }
21
+
22
+ #this is path of given dictionary in my local machine
23
+ dict = D2W::Dictionary.new.dictionary
24
+
25
+ #fetching dictionay in my local dictionary array with leght 3,5,7,4,6,10
26
+ dict = dict.map(&:downcase)
27
+ dictionary = []
28
+ dict.each do |word|
29
+ dictionary << word if [3,4,5,6,7,10].include?(word.length)
30
+ end
31
+ # get all letters for numbers in form of array
32
+
33
+ keys = phone_no.split('').map{|digit| dw_map[digit]}.flatten
34
+
35
+ possible_words = []
36
+
37
+ # filter words which is possible for given phone number
38
+
39
+ dictionary.each do |word|
40
+ if (word.split("") - keys).empty?
41
+ possible_words << word
42
+ end
43
+ end
44
+ exact_words = []
45
+ # filer exact words for phone number from possible words
46
+ possible_words.each do |word|
47
+ exact_words << word if D2W::WordInNumber.new.word_in_number?(phone_no, word, dw_map)
48
+ end
49
+
50
+ p possible_pair = D2W::FilterWordLengthWise.new.filter_word_length_wise(exact_words, phone_no, dw_map)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module D2w
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,38 @@
1
+ module D2W
2
+ class WordCollection
3
+ def word_collection(words)
4
+ possible_pair = []
5
+
6
+ length_3 = words[0]; length_4 = words[1]; length_5 = words[2]; length_6 = words[3]; length_7 = words[4]; length_03 = words[5]; length_04 = words[6]; length_05 = words[7]; length_10 = words[8];
7
+ !length_3.empty? && length_3.each do |word3|
8
+ !length_03.empty? && length_03.each do |word03|
9
+ !length_04.empty? && length_04.each do |word04|
10
+ possible_pair << [word3, word03, word04]
11
+ end
12
+ end
13
+ end
14
+
15
+ !length_3.empty? && length_3.each do |word3|
16
+ !length_7.empty? && length_7.each do |word7|
17
+ possible_pair << [word3, word7]
18
+ end
19
+ end
20
+
21
+ !length_4.empty? && length_4.each do |word4|
22
+ !length_6.empty? && length_6.each do |word6|
23
+ possible_pair << [word4, word6]
24
+ end
25
+ end
26
+
27
+ !length_5.empty? && length_5.each do |word5|
28
+ !length_05.empty? && length_05.each do |word05|
29
+ possible_pair << [word5, word05]
30
+ end
31
+ end
32
+ !length_10.empty? && length_10.each do |word10|
33
+ possible_pair << [word10]
34
+ end
35
+ possible_pair
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ module D2W
2
+ class WordInNumber
3
+ def word_in_number?(phone_no, word, dw_map)
4
+ number = []
5
+ word.split("").each do |char|
6
+ dw_map.each do |k, v|
7
+ if v.include?(char)
8
+ number << k
9
+ break
10
+ end
11
+ end
12
+ end
13
+
14
+ if phone_no.include?number.join("")
15
+ return number.join("")
16
+ end
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: d2w
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - BabalooPatel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: It will help to remeber phone numbers
84
+ email:
85
+ - babaloo@threadsol.com
86
+ executables:
87
+ - d2w
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - d2w.gemspec
101
+ - exe/d2w
102
+ - lib/d2w.rb
103
+ - lib/d2w/cli.rb
104
+ - lib/d2w/dictionary.rb
105
+ - lib/d2w/filter_word_length_wise.rb
106
+ - lib/d2w/phone_to_word.rb
107
+ - lib/d2w/version.rb
108
+ - lib/d2w/word_collection.rb
109
+ - lib/d2w/word_in_number.rb
110
+ homepage: https://github.com/Bablu8993/d2w
111
+ licenses: []
112
+ metadata:
113
+ allowed_push_host: https://rubygems.org/
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.0.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Convert phone number's each digit to character and make a word
133
+ test_files: []