anagram_algo 1.02 → 1.03

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdc6efd05b20b880d552068723471c0f3527c6b76744fa9a42f2e5133b58238e
4
- data.tar.gz: 5ef078f6f1958a2f52d5b8a2723cff3bff72df7f2260a156c647b28072277e25
3
+ metadata.gz: c2f90d41deba14833191e2ea52f6361db1835dff05c6f931cc2c662e2a32c270
4
+ data.tar.gz: 0f70965b66ed8344bcc55d3dd8d1bd448ff4bacc6ffd39049b4b1df222d56b3c
5
5
  SHA512:
6
- metadata.gz: 831a31f94b9d02501d78a0cfaad2b7c03419072ed4507f4457c260b0f2d6198f67f4ee45daa62f323202787bc6d1919bb205b009ef12f50e97eacb19e6c2e469
7
- data.tar.gz: 6c10fc5919ce48c8a8e6395d51a48800d231471b88af4edb7881e39919df8accbb94d20e707ce68d48f79b7efacf1fc92220bff85a52916c1af008dd6e3db088
6
+ metadata.gz: 2ffe09ff093ccf086f3d0cdb7993b0986fb16804392e3c47509d9bc02419f9e70aa0dbb78619e844e11f0736d506b17a5f0fec9a466e9da761cb27b81e0ff2ad
7
+ data.tar.gz: f327ef10a44b637ec746817e11b35f496288e28f1aa1e1622aa52206d6924faecf42aa7686de565c10ac3bec14250b212609909f3ed383dfe9352268ba29430c
data/README.md CHANGED
@@ -3,9 +3,8 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/anagram_algo.svg)](https://badge.fury.io/rb/anagram_algo)
4
4
  [![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- #### AnagramAlgo is a simple algorithm to find and return list of anagrams from your text input. .
6
+ #### AnagramAlgo is a simple algorithm to find and return list of anagrams from your text input.
7
7
 
8
- Note: Currently being moved from local environment to this gem. Will be completed by 7/10/18
9
8
 
10
9
  ## Installation
11
10
 
@@ -25,7 +24,44 @@ Or install it yourself as:
25
24
 
26
25
  ## Usage
27
26
 
28
- Note: Currently being moved from local environment to this gem. Will be completed by 7/10/18
27
+ ### 1) Add your text to a hash with `:text` symbol key, then pass the arguments to `AnagramAlgo.parse(args)` like the example below. If you don't pass any args, and just run `AnagramAlgo.parse` it will return sample data for testing.
28
+
29
+ ```
30
+ args = { text: "Can a rat eat tar? How big is the arc of that car door? Could you pass me the book just below your elbow? Does your state have a coffee taste test? That cider is so sour I cried. It's not good to study in a dusty room. Would you like to see that thing at night? My chin is almost an inch long. Grab something cool to brag about. Don't act like a cat in public, please. It was our Daisy, robed like a princess, but bored all day long. Let's save that vase for later. Can an angel glean upon us? I seriously got stressed from resisting those desserts. Do you ever fluster, or are you always restful? Do you prefer the smell of lemon or melon?" }
31
+
32
+ anagram_hash = AnagramAlgo.parse(args)
33
+ ```
34
+
35
+ ### 2) The returned data will be in hash format like below:
36
+ You can access the data, like so: `anagram_hash[:results]` and `anagram_hash[:text]`
37
+
38
+ ```
39
+ {
40
+ :results=>
41
+ [
42
+ {:string=>"Can a rat eat tar", :anagrams=>"rat, tar"},
43
+ {:string=>"How big is the arc of that car door", :anagrams=>"arc, car"},
44
+ {:string=>"Could you pass me the book just below your elbow", :anagrams=>"below, elbow"},
45
+ {:string=>"Does your state have a coffee taste test", :anagrams=>"state, taste"},
46
+ {:string=>"That cider is so sour I cried", :anagrams=>"cider, cried"},
47
+ {:string=>"It's not good to study in a dusty room", :anagrams=>"dusty, study"},
48
+ {:string=>"Would you like to see that thing at night", :anagrams=>"night, thing"},
49
+ {:string=>"My chin is almost an inch long", :anagrams=>"chin, inch"},
50
+ {:string=>"Grab something cool to brag about", :anagrams=>"brag, grab"},
51
+ {:string=>"Don't act like a cat in public, please", :anagrams=>"act, cat"},
52
+ {:string=>"It was our Daisy, robed like a princess, but bored all day long", :anagrams=>"bored, robed"},
53
+ {:string=>"Let's save that vase for later", :anagrams=>"save, vase"},
54
+ {:string=>"Can an angel glean upon us", :anagrams=>"angel, glean"},
55
+ {:string=>"I seriously got stressed from resisting those desserts", :anagrams=>"desserts, stressed"},
56
+ {:string=>"Do you ever fluster, or are you always restful", :anagrams=>"fluster, restful"},
57
+ {:string=>"Do you prefer the smell of lemon or melon", :anagrams=>"lemon, melon"}
58
+ ],
59
+ :text=>
60
+ "Can a rat eat tar? How big is the arc of that car door? Could you pass me the book just below your elbow? Does your state have a coffee taste test? That cider is so sour I cried. It's not good to study in a dusty room. Would you like to see that thing at night? My chin is almost an inch long. Grab something cool to brag about. Don't act like a cat in public, please. It was our Daisy, robed like a princess, but bored all day long. Let's save that vase for later. Can an angel glean upon us? I seriously got stressed from resisting those desserts. Do you ever fluster, or are you always restful? Do you prefer the smell of lemon or melon?"
61
+ }
62
+ ```
63
+
64
+
29
65
 
30
66
  ## Development
31
67
 
data/Rakefile CHANGED
@@ -18,18 +18,18 @@ task :console do
18
18
  require "active_support/all"
19
19
  ARGV.clear
20
20
 
21
- scraped_links = run_sudoku
22
- # binding.pry
21
+ anagram_hash = run_anagram
23
22
 
24
23
  IRB.start
25
24
  end
26
25
 
27
26
 
28
- def run_sudoku
29
- binding.pry
30
- solve = AnagramAlgo::Solver.new
31
- res = solve.start
32
- binding.pry
27
+ def run_anagram
28
+ # args = {text: "Can a rat eat tar? How big is the arc of that car door? Could you pass me the book just below your elbow? Does your state have a coffee taste test?" }
29
+
30
+ args = { text: "Can a rat eat tar? How big is the arc of that car door? Could you pass me the book just below your elbow? Does your state have a coffee taste test? That cider is so sour I cried. It's not good to study in a dusty room. Would you like to see that thing at night? My chin is almost an inch long. Grab something cool to brag about. Don't act like a cat in public, please. It was our Daisy, robed like a princess, but bored all day long. Let's save that vase for later. Can an angel glean upon us? I seriously got stressed from resisting those desserts. Do you ever fluster, or are you always restful? Do you prefer the smell of lemon or melon?" }
31
+
32
+ anagram_hash = AnagramAlgo.parse(args)
33
33
 
34
34
  # scraper = LinkScraper::Scrape.new({text_criteria: text_criteria, path_criteria: path_criteria})
35
35
  # scraped_links = scraper.start('https://en.wikipedia.org/wiki/Austin%2C_Texas')
@@ -2,16 +2,57 @@
2
2
  module AnagramAlgo
3
3
  class Solver
4
4
 
5
- def initialize
6
- binding.pry
5
+ # AlgoService.new.run_anagrams({string: 'lemon apple madam cinema restful fluster'})
6
+ def run_anagrams(args = {})
7
+ string_block = args.fetch(:text, nil)
8
+ string_block = sample_string_block if !string_block.present?
9
+ parsed_strings = parse_string_block(string_block)
10
+
11
+ results = parsed_strings.map do |string|
12
+ { string: string, anagrams: find_anagrams(string) }
13
+ end
14
+
15
+ anagram_hash = { results: results, text: string_block }
16
+ end
17
+
18
+
19
+ def parse_string_block(string_block)
20
+ strings = string_block.split(/\.\s+|!|\?/)
21
+ strings = strings.map { |str| str.squeeze(' ') }
22
+ strings = strings.map(&:strip)
23
+ end
24
+
25
+
26
+ # array = ['madam', 'restful', 'fluster']
27
+ def find_anagrams(word_string)
28
+ original_strs = word_string.downcase.split(/\W+/).sort
29
+ string_hsh = original_strs.zip(original_strs).to_h
30
+ string_hsh.map { |k,v| string_hsh[v] = format_string(v) }
31
+ anagrams = anagrams_in_string_hsh(string_hsh)
32
+ end
33
+
34
+ def anagrams_in_string_hsh(string_hsh)
35
+ duplicates = find_duplicates(string_hsh.values)
36
+ anagrams = string_hsh.select do |k, v|
37
+ duplicates.include?(v)
38
+ end
39
+ anagrams = anagrams.keys.join(', ')
7
40
  end
8
41
 
9
- def start
10
- binding.pry
11
- "testing setup"
42
+ def find_duplicates(formatted_strs)
43
+ duplicates = formatted_strs.select do |str|
44
+ formatted_strs.count(str) > 1
45
+ end
46
+ duplicates.uniq
12
47
  end
13
48
 
49
+ def format_string(string)
50
+ formatted_string = string.downcase.chars.sort.join('')
51
+ end
14
52
 
53
+ def sample_string_block
54
+ "Can a rat eat tar? How big is the arc of that car door? Could you pass me the book just below your elbow? Does your state have a coffee taste test? That cider is so sour I cried. It's not good to study in a dusty room. Would you like to see that thing at night? My chin is almost an inch long. Grab something cool to brag about. Don't act like a cat in public, please. It was our Daisy, robed like a princess, but bored all day long. Let's save that vase for later. Can an angel glean upon us? I seriously got stressed from resisting those desserts. Do you ever fluster, or are you always restful? Do you prefer the smell of lemon or melon?"
55
+ end
15
56
 
16
57
  end
17
58
  end
@@ -1,3 +1,3 @@
1
1
  module AnagramAlgo
2
- VERSION = "1.02"
2
+ VERSION = "1.03"
3
3
  end
data/lib/anagram_algo.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require "anagram_algo/version"
2
-
3
2
  require "anagram_algo/solver"
4
- # require 'mechanizer'
5
- # require 'scrub_db'
6
3
  require 'pry'
7
4
 
8
5
  module AnagramAlgo
9
- # Your code goes here...
6
+
7
+ def self.parse(args={})
8
+ anagram_hash = self::Solver.new.run_anagrams(args)
9
+ end
10
+
10
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anagram_algo
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.02'
4
+ version: '1.03'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Booth
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-05 00:00:00.000000000 Z
11
+ date: 2018-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport