lita-wolfram-alpha 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/lita/handlers/wolfram_alpha.rb +16 -4
- data/lita-wolfram-alpha.gemspec +1 -1
- data/spec/lita/handlers/wolfram_alpha_spec.rb +20 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25305ff0dfbb1bdaee1124d6fcdff9fd2f3d5a9c
|
4
|
+
data.tar.gz: f3e634e4a6b4954ce0532f6172bda36be9d76689
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: babb79e4ee75e6bf621ae413a0e3c732850a002833e229fcdbbae956208062bac14047a602ceedcaa5b18d47beab01147294ce97f50f716999b163115575beba
|
7
|
+
data.tar.gz: 74c83bc1481b2e6614cf1c5f64824da78aa3f57cdec2fb3d4358c538baf47673b484b682daf45184a8cc20fc1bd1a8614da36f9868d3fdee880bd924325cc95d
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/tristaneuan/lita-wolfram-alpha.png?branch=master)](https://travis-ci.org/tristaneuan/lita-wolfram-alpha)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/tristaneuan/lita-wolfram-alpha/badge.png)](https://coveralls.io/r/tristaneuan/lita-wolfram-alpha)
|
5
5
|
|
6
|
-
**lita-wolfram-alpha** is a handler for [Lita](https://github.com/jimmycuadra/lita) that performs Wolfram Alpha queries. [Wolfram Alpha](http://www.wolframalpha.com/) is a computational knowledge engine that draws upon a comprehensive knowledge base of curated structured data to answer a wide variety of
|
6
|
+
**lita-wolfram-alpha** is a handler for [Lita](https://github.com/jimmycuadra/lita) that performs Wolfram Alpha queries. [Wolfram Alpha](http://www.wolframalpha.com/) is a computational knowledge engine that draws upon a comprehensive knowledge base of curated structured data to answer questions spanning a wide variety of topics.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -23,6 +23,15 @@ Lita.configure do |config|
|
|
23
23
|
end
|
24
24
|
```
|
25
25
|
|
26
|
+
### Optional attributes
|
27
|
+
* `hide_link` (boolean) - By default, Lita returns a Wolfram Alpha link containing additional information after providing the best answer. If `hide_link` is set to true, this link is omitted.
|
28
|
+
|
29
|
+
``` ruby
|
30
|
+
Lita.configure do |config|
|
31
|
+
config.handlers.wolfram_alpha.hide_link = true
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
26
35
|
## Usage
|
27
36
|
|
28
37
|
Specify a [Wolfram Alpha query](http://www.wolframalpha.com/examples/?src=input) using the `wa` command.
|
@@ -35,6 +44,7 @@ Specify a [Wolfram Alpha query](http://www.wolframalpha.com/examples/?src=input)
|
|
35
44
|
<lita> Tagalog | 765033 people
|
36
45
|
<lita> Vietnamese | 512456 people
|
37
46
|
<lita> (2008-2012 American Community Survey 5-year estimates)
|
47
|
+
<lita> Learn more: http://www.wolframalpha.com/input/?i=most+commonly+spoken+languages+in+california
|
38
48
|
```
|
39
49
|
|
40
50
|
## License
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "cgi"
|
1
2
|
require "nokogiri"
|
2
3
|
|
3
4
|
module Lita
|
@@ -7,6 +8,7 @@ module Lita
|
|
7
8
|
API_URL = "http://api.wolframalpha.com/v2/query"
|
8
9
|
|
9
10
|
config :app_id, type: String, required: true
|
11
|
+
config :hide_link, types: [TrueClass, FalseClass], default: false
|
10
12
|
|
11
13
|
route(/^wa\s+(.+)/i, :query, command: true,
|
12
14
|
help: {t("help.query_key") => t("help.query_value")})
|
@@ -20,11 +22,21 @@ module Lita
|
|
20
22
|
appid: config.app_id
|
21
23
|
)
|
22
24
|
return if http_response.status != 200
|
25
|
+
link = "Learn more: http://www.wolframalpha.com/input/?i=#{CGI.escape(input)}"
|
23
26
|
xml = Nokogiri::XML(http_response.body)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
primary = xml.at_xpath("//pod[@primary='true']//plaintext[string-length(text()) > 0]")
|
28
|
+
if primary
|
29
|
+
response.reply primary.content
|
30
|
+
response.reply link unless config.hide_link
|
31
|
+
else
|
32
|
+
secondary = xml.at_xpath("//pod[not(@id='Input')]//plaintext[string-length(text()) > 0]")
|
33
|
+
if secondary
|
34
|
+
response.reply secondary.content
|
35
|
+
response.reply link unless config.hide_link
|
36
|
+
else
|
37
|
+
response.reply "¯\\_(ツ)_/¯"
|
38
|
+
end
|
39
|
+
end
|
28
40
|
end
|
29
41
|
|
30
42
|
end
|
data/lita-wolfram-alpha.gemspec
CHANGED
@@ -10,16 +10,32 @@ describe Lita::Handlers::WolframAlpha, lita_handler: true do
|
|
10
10
|
|
11
11
|
describe "#query" do
|
12
12
|
|
13
|
-
it "returns the primary pod's plaintext
|
13
|
+
it "returns the primary pod's plaintext" do
|
14
14
|
send_command "wa pi"
|
15
|
-
expect(replies.count).to eq
|
15
|
+
expect(replies.count).to eq 2
|
16
16
|
expect(replies.first).to match(/^3\.14159/)
|
17
|
+
expect(replies.last).to match(/^Learn more: http:\/\/www\.wolframalpha\.com\/input\/\?i=pi$/)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns the first subpod containing plaintext when the primary pod has multiple subpods" do
|
21
|
+
send_command "wa sky chart"
|
22
|
+
expect(replies.count).to eq 2
|
23
|
+
expect(replies.first).to match(/^\d+\^h \d+\^m [\d\.]+\^s$/)
|
24
|
+
expect(replies.last).to match(/^Learn more: http:\/\/www\.wolframalpha\.com\/input\/\?i=sky\+chart$/)
|
17
25
|
end
|
18
26
|
|
19
|
-
it "returns the first non-input, non-empty pod's plaintext
|
27
|
+
it "returns the first non-input, non-empty pod's plaintext when no primary pod exists" do
|
20
28
|
send_command "wa U+00F8"
|
21
|
-
expect(replies.count).to eq
|
29
|
+
expect(replies.count).to eq 2
|
22
30
|
expect(replies.first).to match(/^Latin small letter o with stroke/)
|
31
|
+
expect(replies.last).to match(/^Learn more: http:\/\/www\.wolframalpha\.com\/input\/\?i=U%2B00F8$/)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not return a link if hide_link is true" do
|
35
|
+
registry.config.handlers.wolfram_alpha.hide_link = true
|
36
|
+
send_command "wa pi"
|
37
|
+
expect(replies.count).to eq 1
|
38
|
+
expect(replies.first).to match(/^3\.14159/)
|
23
39
|
end
|
24
40
|
|
25
41
|
it "returns a shrug emoticon for an unrecognized query" do
|