wolfram_alpha 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,11 @@
1
+ = wolfram_alpha
2
+
3
+ Unofficial simple wolfram alpha api.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * initial release
8
+
9
+ == Copyright
10
+
11
+ * See license
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "wolfram_alpha"
8
+ gem.summary = %Q{query wolfram alpha from your ruby environment}
9
+ gem.description = %Q{wa = Wolfram_Alpha.new || wa.query = "gdp of France" || wa.submit || wa.get_results "text"}
10
+ gem.version = "0.0.1"
11
+ gem.email = "phunny.phacts@gmail.com"
12
+ gem.homepage = "http://tech-labs.net"
13
+ gem.authors = ["Mark Fayngersh"]
14
+ gem.add_development_dependency "Hpricot", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "wolfram_alpha #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
@@ -0,0 +1,56 @@
1
+ # Very basic API that parses Wolfram Alpha queries.
2
+ # Meant to serve as an alternative to the rather expensive official API.
3
+ #
4
+ # Mark Fayngersh.
5
+ # http://tech-labs.net
6
+
7
+ require 'rubygems'
8
+ require 'hpricot'
9
+ require 'open-uri'
10
+
11
+ #Example:
12
+ # => wa = Wolfram_Alpha.new
13
+ # => wa.query = "Capital of New York"
14
+ # => wa.submit
15
+ #
16
+ # => wa.get_results
17
+ # => wa.get_results "text"
18
+ # => wa.get_results "description"
19
+ # => wa.get_results "image"
20
+ #
21
+ # => wa.get_results.collect { |n| "Description: #{n['desc']} "}
22
+ class Wolfram_Alpha
23
+ attr_accessor :query
24
+
25
+ #parses page containing query results into an Hpricot tree and initializes @results with a hash-map of key-value pairs of the results.
26
+ def submit
27
+ doc = Hpricot(open("http://www.wolframalpha.com/input/?i=#{URI.escape(query)}"))
28
+ l = []
29
+
30
+ #iterate through each result pod
31
+ doc.at("div#results").search("div[@class='pod ']").each do |pod|
32
+ m = {}
33
+ m.update("image_url" => pod.at("div[@class='output'] img").attributes['src'])
34
+ m.update("text" => pod.at("div[@class='output'] img").attributes['alt'])
35
+ m.update("desc" => pod.at("h1").inner_text)
36
+ l << m
37
+ end
38
+
39
+ @results = l
40
+ "Query submitted."
41
+ end
42
+
43
+ #returns filtered results according to argument. Returns all results if no argument supplied.
44
+ def get_results(*options)
45
+ if options[0] == "image" #returns url of image result
46
+ @results.collect { |n| n['image_url'] }.join(" ")
47
+ elsif options[0] == "description" #returns description of the result
48
+ @results.collect { |n| n['desc'] }.join(" ")
49
+ elsif options[0] == "text" # returns the result in text format
50
+ @results.collect { |n| n['text'] }.join(" ")
51
+ else
52
+ @results
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'wolfram_alpha'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestWolframAlpha < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wolfram_alpha
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Fayngersh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-01 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: Hpricot
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: wa = Wolfram_Alpha.new || wa.query = "gdp of France" || wa.submit || wa.get_results "text"
26
+ email: phunny.phacts@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - lib/wolfram_alpha.rb
41
+ - test/helper.rb
42
+ - test/test_wolfram_alpha.rb
43
+ has_rdoc: true
44
+ homepage: http://tech-labs.net
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --charset=UTF-8
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.5
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: query wolfram alpha from your ruby environment
71
+ test_files:
72
+ - test/helper.rb
73
+ - test/test_wolfram_alpha.rb