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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 029b9f75239f83d7717398c8198484f52e00da24
4
- data.tar.gz: 873c6649cf95241dd05bcf57aab5d8d116cd64d9
3
+ metadata.gz: 25305ff0dfbb1bdaee1124d6fcdff9fd2f3d5a9c
4
+ data.tar.gz: f3e634e4a6b4954ce0532f6172bda36be9d76689
5
5
  SHA512:
6
- metadata.gz: 5381aab861a29ae760833b5072a6cad5da40ee642bac7c5a028eae9a2365407a0c95a25186be20bd8d237a5f997a5d58167cb5142b6b991efe84e72eaffc610b
7
- data.tar.gz: 3e45858162b3b772c3ad1283ba730cf2226e3420d1de390cfefd9558c533048c9fb2e0fb9bcb2d3ae5bf3bf5304e90e1a132a4fa495aa1db05148dd5899aa0fa
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 questions.
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
- result = xml.at_xpath("//pod[@primary='true']//plaintext")
25
- return response.reply result.content if result
26
- result = xml.at_xpath("//pod[not(@title='Input interpretation')]//plaintext[string-length(text()) > 0]")
27
- response.reply result ? result.content : "¯\\_(ツ)_/¯"
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-wolfram-alpha"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.1.1"
4
4
  spec.authors = ["Tristan Chong"]
5
5
  spec.email = ["ong@tristaneuan.ch"]
6
6
  spec.description = "A Lita handler that performs Wolfram Alpha queries."
@@ -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 for a valid query" do
13
+ it "returns the primary pod's plaintext" do
14
14
  send_command "wa pi"
15
- expect(replies.count).to eq 1
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 for a valid query when no primary pod exists" do
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 1
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-wolfram-alpha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Chong