whatsa 0.2.1 → 0.2.2
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 +4 -4
 - data/README.md +2 -2
 - data/lib/whatsa/cli.rb +23 -13
 - data/lib/whatsa/disambig.rb +1 -1
 - data/lib/whatsa/section.rb +1 -1
 - data/lib/whatsa/version.rb +1 -1
 - data/whatsa.gemspec +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 7ac4a4382455cb767f687b48ee577cfbea776f34
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ee220697878ad879a70bac12da3eb7dd84f54a2c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 02c69d6cc696b0e5d8b185de1b0634a335bf154660ed6d31790b03a4e891b5fe8cc3e9959743581c570d1a8206856f6c220348b921d08b5334586126ee12989f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 372691d81e21c453a06c37c5cc6365641cdc3922f3375c2e908cabda78d215e7a85afa9fe369877f903cbba13c79e5847a12accac1e4f09db7ac7a333febf2c4
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -8,7 +8,7 @@ Whatsa is a CLI app that allows you to search a word or phrase and receive a qui 
     | 
|
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            ### How does it do that?
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
            It searches your query on Wikipedia and finds the page you're most likely looking for. If you've been somewhat vague, or your search term could refer to multiple things, it will ask you to select from a disambiguation of topics. Usually, however, your term will go straight to an article. Whatsa then gives you the first paragraph of that article ( 
     | 
| 
      
 11 
     | 
    
         
            +
            It searches your query on Wikipedia and finds the page you're most likely looking for. If you've been somewhat vague, or your search term could refer to multiple things, it will ask you to select from a disambiguation of topics. Usually, however, your term will go straight to an article. Whatsa then gives you the first paragraph of that article (often a surprisingly decent summary).
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
            If you're not super satisfied with that bit of information (and you need to know a little more) you can type `more` to get a better picture of that subject. If you're _still_ not satisfied, and you want to know something _specific_ about the thing you've searched, type `other`, and it will list the categories of information Wikipedia knows about the subject (its "History", "Early Life", "Uses", etc.). You can select one of those sections, if you'd like, and it will give you the first paragraph of that section, too (which you can extend similarly with another `more` command). You can make a new query with `new`, ask for help at any time with `help`, or exit the application with `exit`.
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
         @@ -18,7 +18,7 @@ Simple! 
     | 
|
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
            ### No, but like, _how_ does it do that?
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
            You can find a little more information in a blog post I made 
     | 
| 
      
 21 
     | 
    
         
            +
            You can find a little more information in a [blog post I made](http://cogsandcurves.com/2016/11/28/so_you_made_a_cli_data_gem_eh/)!
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
            ## Installing Whatsa
         
     | 
| 
       24 
24 
     | 
    
         | 
    
        data/lib/whatsa/cli.rb
    CHANGED
    
    | 
         @@ -1,7 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Whatsa::CLI
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
              def  
     | 
| 
      
 3 
     | 
    
         
            +
              def clear_screen
         
     | 
| 
      
 4 
     | 
    
         
            +
                50.times { puts "\n" }
         
     | 
| 
       4 
5 
     | 
    
         
             
                system('clear')
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              def welcome
         
     | 
| 
      
 9 
     | 
    
         
            +
                clear_screen
         
     | 
| 
       5 
10 
     | 
    
         
             
                puts "Whatsa is a quick-and-dirty lookup utility, powered by Wikipedia!"
         
     | 
| 
       6 
11 
     | 
    
         
             
                puts "-----------------------------------------------------------------"
         
     | 
| 
       7 
12 
     | 
    
         
             
              end
         
     | 
| 
         @@ -39,14 +44,15 @@ class Whatsa::CLI 
     | 
|
| 
       39 
44 
     | 
    
         
             
                input
         
     | 
| 
       40 
45 
     | 
    
         
             
              end
         
     | 
| 
       41 
46 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
               
     | 
| 
      
 47 
     | 
    
         
            +
              # setting an indent will indent the lines AFTER the first line of a paragraph
         
     | 
| 
      
 48 
     | 
    
         
            +
              def word_wrap(text, indent=0)
         
     | 
| 
       43 
49 
     | 
    
         
             
                count = 0
         
     | 
| 
       44 
50 
     | 
    
         
             
                words = text.split(/ /)
         
     | 
| 
       45 
51 
     | 
    
         
             
                words.each_with_index do |word, index|
         
     | 
| 
       46 
52 
     | 
    
         
             
                  count += word.length + 1
         
     | 
| 
       47 
53 
     | 
    
         
             
                  if count > 80
         
     | 
| 
       48 
     | 
    
         
            -
                    words.insert(index, "\n")
         
     | 
| 
       49 
     | 
    
         
            -
                    count =  
     | 
| 
      
 54 
     | 
    
         
            +
                    words.insert(index, "\n#{' ' * indent}")
         
     | 
| 
      
 55 
     | 
    
         
            +
                    count = indent
         
     | 
| 
       50 
56 
     | 
    
         
             
                  elsif word.index("\n")
         
     | 
| 
       51 
57 
     | 
    
         
             
                    count = word.length
         
     | 
| 
       52 
58 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -56,21 +62,25 @@ class Whatsa::CLI 
     | 
|
| 
       56 
62 
     | 
    
         | 
| 
       57 
63 
     | 
    
         
             
              def display_dmb(dmb)
         
     | 
| 
       58 
64 
     | 
    
         
             
                raise TypeError unless dmb.is_a?(Whatsa::Disambig)
         
     | 
| 
       59 
     | 
    
         
            -
                 
     | 
| 
      
 65 
     | 
    
         
            +
                clear_screen
         
     | 
| 
       60 
66 
     | 
    
         
             
                stripped_title = dmb.title.gsub("(disambiguation)", "").strip
         
     | 
| 
       61 
     | 
    
         
            -
                puts "Hmmm... #{stripped_title} could mean a few different things:\n"
         
     | 
| 
      
 67 
     | 
    
         
            +
                puts word_wrap("Hmmm... #{stripped_title} could mean a few different things:\n")
         
     | 
| 
       62 
68 
     | 
    
         
             
                dmb.descriptions.each_with_index do |kvp, i|
         
     | 
| 
      
 69 
     | 
    
         
            +
                  num = "#{i + 1}. "
         
     | 
| 
      
 70 
     | 
    
         
            +
                  item = "#{kvp[0].to_s}"
         
     | 
| 
       63 
71 
     | 
    
         
             
                  desc = kvp[1].empty? ? "" : " - #{kvp[1]}"
         
     | 
| 
       64 
     | 
    
         
            -
                  puts  
     | 
| 
      
 72 
     | 
    
         
            +
                  puts word_wrap(num + item + desc, num.length)
         
     | 
| 
       65 
73 
     | 
    
         
             
                end
         
     | 
| 
       66 
74 
     | 
    
         
             
                puts "\nPlease select a choice, either by name or number."
         
     | 
| 
       67 
75 
     | 
    
         
             
              end
         
     | 
| 
       68 
76 
     | 
    
         | 
| 
       69 
77 
     | 
    
         
             
              def display_sections(text)
         
     | 
| 
       70 
78 
     | 
    
         
             
                text = text.article if text.is_a?(Whatsa::Section)
         
     | 
| 
       71 
     | 
    
         
            -
                 
     | 
| 
       72 
     | 
    
         
            -
                puts "Here are some specific subjects about '#{text.title}':\n"
         
     | 
| 
       73 
     | 
    
         
            -
                text.section_titles.each_with_index  
     | 
| 
      
 79 
     | 
    
         
            +
                clear_screen
         
     | 
| 
      
 80 
     | 
    
         
            +
                puts word_wrap("Here are some specific subjects about '#{text.title}':\n")
         
     | 
| 
      
 81 
     | 
    
         
            +
                text.section_titles.each_with_index do |title, i|
         
     | 
| 
      
 82 
     | 
    
         
            +
                  puts word_wrap("#{i + 1}. #{title}", "#{i + 1}. ".length)
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
       74 
84 
     | 
    
         
             
                puts "\nPlease select a choice, either by name or number."
         
     | 
| 
       75 
85 
     | 
    
         
             
              end
         
     | 
| 
       76 
86 
     | 
    
         | 
| 
         @@ -105,7 +115,7 @@ class Whatsa::CLI 
     | 
|
| 
       105 
115 
     | 
    
         
             
              end
         
     | 
| 
       106 
116 
     | 
    
         | 
| 
       107 
117 
     | 
    
         
             
              def summarize(text)
         
     | 
| 
       108 
     | 
    
         
            -
                 
     | 
| 
      
 118 
     | 
    
         
            +
                clear_screen
         
     | 
| 
       109 
119 
     | 
    
         
             
                return full(text) if text.summary == text.full_text
         
     | 
| 
       110 
120 
     | 
    
         
             
                puts word_wrap(text.summary)
         
     | 
| 
       111 
121 
     | 
    
         
             
                summary_helpline
         
     | 
| 
         @@ -114,7 +124,7 @@ class Whatsa::CLI 
     | 
|
| 
       114 
124 
     | 
    
         
             
              end
         
     | 
| 
       115 
125 
     | 
    
         | 
| 
       116 
126 
     | 
    
         
             
              def full(text)
         
     | 
| 
       117 
     | 
    
         
            -
                 
     | 
| 
      
 127 
     | 
    
         
            +
                clear_screen
         
     | 
| 
       118 
128 
     | 
    
         
             
                puts word_wrap(text.full_text)
         
     | 
| 
       119 
129 
     | 
    
         
             
                full_text_helpline
         
     | 
| 
       120 
130 
     | 
    
         
             
                gets_command
         
     | 
| 
         @@ -148,7 +158,7 @@ class Whatsa::CLI 
     | 
|
| 
       148 
158 
     | 
    
         | 
| 
       149 
159 
     | 
    
         
             
                # get an article from the search, or restart the loop if it can't be found
         
     | 
| 
       150 
160 
     | 
    
         
             
                if scraper.not_found?
         
     | 
| 
       151 
     | 
    
         
            -
                  print "Hmmm... I don't know what '#{input}' means!\nPress 'enter' to try something else."
         
     | 
| 
      
 161 
     | 
    
         
            +
                  print word_wrap("Hmmm... I don't know what '#{input}' means!\nPress 'enter' to try something else.")
         
     | 
| 
       152 
162 
     | 
    
         
             
                  gets
         
     | 
| 
       153 
163 
     | 
    
         
             
                  run
         
     | 
| 
       154 
164 
     | 
    
         
             
                elsif scraper.disambig?
         
     | 
    
        data/lib/whatsa/disambig.rb
    CHANGED
    
    | 
         @@ -32,7 +32,7 @@ class Whatsa::Disambig 
     | 
|
| 
       32 
32 
     | 
    
         
             
                    all_link = key.match("All pages with titles")
         
     | 
| 
       33 
33 
     | 
    
         
             
                    unless toc_link || dmb_link || all_link
         
     | 
| 
       34 
34 
     | 
    
         
             
                      desc = item.text.split("\n").first.strip
         
     | 
| 
       35 
     | 
    
         
            -
                      memo[key] = desc.gsub(key 
     | 
| 
      
 35 
     | 
    
         
            +
                      memo[key] = desc.gsub(/^#{Regexp.escape(key)}[^\w"]/, "").strip
         
     | 
| 
       36 
36 
     | 
    
         
             
                    end
         
     | 
| 
       37 
37 
     | 
    
         
             
                  end
         
     | 
| 
       38 
38 
     | 
    
         
             
                  memo
         
     | 
    
        data/lib/whatsa/section.rb
    CHANGED
    
    
    
        data/lib/whatsa/version.rb
    CHANGED
    
    
    
        data/whatsa.gemspec
    CHANGED
    
    | 
         @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| 
     | 
|
| 
       10 
10 
     | 
    
         
             
              spec.email         = ["kjleitz@gmail.com"]
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
              spec.summary       = %q{What is that? Okay, okay, I don't need a lecture... just gimme the short 'n sweet!}
         
     | 
| 
       13 
     | 
    
         
            -
              spec.description   = %q{Whatsa is a CLI app that allows you to search a word or phrase and receive a quick summary about that subject. It searches your query on Wikipedia and finds the page you're most likely looking for. If you've been somewhat vague, or your search term could refer to multiple things, it will ask you to select from a disambiguation of topics. Usually, however, your term will go straight to an article. Whatsa then gives you the first paragraph of that article ( 
     | 
| 
      
 13 
     | 
    
         
            +
              spec.description   = %q{Whatsa is a CLI app that allows you to search a word or phrase and receive a quick summary about that subject. It searches your query on Wikipedia and finds the page you're most likely looking for. If you've been somewhat vague, or your search term could refer to multiple things, it will ask you to select from a disambiguation of topics. Usually, however, your term will go straight to an article. Whatsa then gives you the first paragraph of that article (often a surprisingly decent summary).
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
            If you're not super satisfied with that bit of information (and you need to know a little more) you can type `more` to get a better picture of that subject. If you're _still_ not satisfied, and you want to know something _specific_ about the thing you've searched, type `other`, and it will list the categories of information Wikipedia knows about the subject (its "History", "Early Life", "Uses", etc.). You can select one of those sections, if you'd like, and it will give you the first paragraph of that section, too (which you can extend similarly with another `more` command). You can make a new query with `new`, ask for help at any time with `help`, or exit the application with `exit`.}
         
     | 
| 
       16 
16 
     | 
    
         
             
              spec.homepage      = "https://github.com/kjleitz/whatsa"
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: whatsa
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Keegan Leitz
         
     | 
| 
         @@ -67,7 +67,7 @@ dependencies: 
     | 
|
| 
       67 
67 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       68 
68 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       69 
69 
     | 
    
         
             
            description: |-
         
     | 
| 
       70 
     | 
    
         
            -
              Whatsa is a CLI app that allows you to search a word or phrase and receive a quick summary about that subject. It searches your query on Wikipedia and finds the page you're most likely looking for. If you've been somewhat vague, or your search term could refer to multiple things, it will ask you to select from a disambiguation of topics. Usually, however, your term will go straight to an article. Whatsa then gives you the first paragraph of that article ( 
     | 
| 
      
 70 
     | 
    
         
            +
              Whatsa is a CLI app that allows you to search a word or phrase and receive a quick summary about that subject. It searches your query on Wikipedia and finds the page you're most likely looking for. If you've been somewhat vague, or your search term could refer to multiple things, it will ask you to select from a disambiguation of topics. Usually, however, your term will go straight to an article. Whatsa then gives you the first paragraph of that article (often a surprisingly decent summary).
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
72 
     | 
    
         
             
              If you're not super satisfied with that bit of information (and you need to know a little more) you can type `more` to get a better picture of that subject. If you're _still_ not satisfied, and you want to know something _specific_ about the thing you've searched, type `other`, and it will list the categories of information Wikipedia knows about the subject (its "History", "Early Life", "Uses", etc.). You can select one of those sections, if you'd like, and it will give you the first paragraph of that section, too (which you can extend similarly with another `more` command). You can make a new query with `new`, ask for help at any time with `help`, or exit the application with `exit`.
         
     | 
| 
       73 
73 
     | 
    
         
             
            email:
         
     |