oeis 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in oeis.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # OEIS
2
+
3
+ ## About
4
+
5
+ This a gem to interface the [On-Line Encyclopedia of Integer Sequences](http://oeis.org)
6
+ (OEIS). It allows you to search for a documented sequence using a Ruby Fixnum Array as
7
+ input.
8
+
9
+ ## Usage
10
+
11
+ > require 'oeis'
12
+ > l = 3.upto(10).collect { |i| i*i }
13
+ > result = OEIS::Search(l)
14
+
15
+ > p result.title
16
+ The squares: a(n) = n^2.
17
+ > p result.id
18
+ A000290
19
+ > p result.sequence
20
+ [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ...
21
+
22
+ ## Installation
23
+
24
+ git clone git@github.com:prezjordan/oeis.git
25
+ cd oeis
26
+ bundle
27
+ gem build oeis.gemspec
28
+ gem install oeis-0.0.1
29
+
30
+ **OR**
31
+
32
+ gem install oeis
33
+
34
+ ## Why?
35
+
36
+ I started working on this gem after my roommate's snoring kept me from sleeping. It is my
37
+ first gem, so there's a *very* good chance I did something wrong, or did something
38
+ not-so-right.
39
+
40
+ Numbers have always been a passion of mine, so this servers as a simple educational tool.
41
+ Generating numbers is fun, seeing various properties of the numbers you just generated is
42
+ even cooler.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/oeis.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "oeis/version"
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ module OEIS
6
+ # Your code goes here...
7
+ class OEIS
8
+
9
+ BASE_URL = 'http://oeis.org/search?q='
10
+
11
+ attr_accessor :id, :title, :sequence
12
+
13
+ def initialize(l)
14
+ url = BASE_URL + l.join(',')
15
+ doc = Nokogiri::HTML(open(url))
16
+
17
+ first_result = doc.css('table table:eq(2)').first
18
+ info = first_result.css('tr:eq(3) table > tr > td > a').first
19
+
20
+ @id = info.attributes['href'].value[1..-1]
21
+ @title = info.attributes['title'].value
22
+
23
+ digits = first_result.css('tr:eq(4) table tr tt').text.split(', ')
24
+ @sequence = digits.map { |a| a.to_i }
25
+ end
26
+
27
+ end
28
+
29
+ def self.Search(l)
30
+ OEIS.new(l)
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Oeis
2
+ VERSION = "0.0.2"
3
+ end
data/oeis.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "oeis/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "oeis"
7
+ s.version = Oeis::VERSION
8
+ s.authors = ["Jordan Scales"]
9
+ s.email = ["scalesjordan@gmail.com"]
10
+ s.homepage = "http://github.com/prezjordan/oeis"
11
+ s.summary = %q{On-Line Encyclopedia of Integer Sequences gem}
12
+ s.description = %q{Allows you to fetch results from OEIS using a list of integers}
13
+
14
+ s.rubyforge_project = "oeis"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "nokogiri"
23
+ s.add_runtime_dependency "nokogiri"
24
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oeis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jordan Scales
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &70362600493200 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70362600493200
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70362600492780 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70362600492780
36
+ description: Allows you to fetch results from OEIS using a list of integers
37
+ email:
38
+ - scalesjordan@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - README.md
46
+ - Rakefile
47
+ - lib/oeis.rb
48
+ - lib/oeis/version.rb
49
+ - oeis.gemspec
50
+ homepage: http://github.com/prezjordan/oeis
51
+ licenses: []
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project: oeis
70
+ rubygems_version: 1.8.6
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: On-Line Encyclopedia of Integer Sequences gem
74
+ test_files: []