oeis 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -40,4 +40,8 @@ not-so-right.
40
40
 
41
41
  Numbers have always been a passion of mine, so this servers as a simple educational tool.
42
42
  Generating numbers is fun, seeing various properties of the numbers you just generated is
43
- even cooler.
43
+ even cooler.
44
+
45
+ ## LICENSE
46
+
47
+ Include license information here.
@@ -0,0 +1,18 @@
1
+ require 'oeis'
2
+
3
+ ## Thue-Morse Sequence
4
+ ## Starting with a single-element array of 0, continuously add the "inverse" of the array
5
+ ## 0 -> 01 -> 0110 -> 01101001 -> ...
6
+
7
+ seq = [0]
8
+ a = 1
9
+
10
+ 4.times do
11
+ 0.upto(a-1) do |i|
12
+ seq << ((seq[i] == 0) ? 1 : 0)
13
+ end
14
+ a *= 2
15
+ end
16
+
17
+ res = OEIS::search(seq)
18
+ puts "#{res.id}: #{res.title}"
data/lib/oeis.rb CHANGED
@@ -3,43 +3,38 @@ require 'nokogiri'
3
3
  require 'open-uri'
4
4
 
5
5
  module OEIS
6
- # Your code goes here...
7
- class OEISParser
8
-
6
+ class Parser
7
+
9
8
  BASE_URL = 'http://oeis.org/search?q='
10
-
9
+
11
10
  attr_accessor :id, :title, :sequence
12
-
11
+
13
12
  def initialize(ls)
14
13
  url = BASE_URL + ls.join(',')
15
- begin
16
- doc = Nokogiri::HTML(open(url))
17
- rescue SocketError
18
- puts 'Connection could not be established. Check your internet connection.'
19
- end
20
-
14
+ doc = Nokogiri::HTML(open(url))
15
+
21
16
  first_result = doc.css('table table:eq(2)').first
22
17
  info = first_result.css('tr:eq(3) table > tr > td > a').first
23
-
18
+
24
19
  if info.nil?
25
20
  puts 'No sequence found.'
26
21
  return nil
27
22
  end
28
-
23
+
29
24
  @id = info.attributes['href'].value[1..-1]
30
25
  @title = info.attributes['title'].value
31
-
26
+
32
27
  digits = first_result.css('tr:eq(4) table tr tt').text.split(', ')
33
28
  @sequence = digits.map &:to_i
34
29
  end
35
-
30
+
36
31
  def to_s
37
32
  "#{@id}: #{@title}"
38
33
  end
39
-
34
+
40
35
  end
41
-
36
+
42
37
  def self.search(ls)
43
- OEISParser.new(ls)
38
+ OEIS::Parser.new(ls)
44
39
  end
45
40
  end
data/lib/oeis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Oeis
2
- VERSION = "0.0.3"
1
+ module OEIS
2
+ VERSION = "0.0.4"
3
3
  end
data/oeis.gemspec CHANGED
@@ -4,7 +4,7 @@ require "oeis/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "oeis"
7
- s.version = Oeis::VERSION
7
+ s.version = OEIS::VERSION
8
8
  s.authors = ["Jordan Scales"]
9
9
  s.email = ["scalesjordan@gmail.com"]
10
10
  s.homepage = "http://github.com/prezjordan/oeis"
@@ -18,7 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # specify any dependencies here; for example:
22
- s.add_development_dependency "nokogiri"
23
- s.add_runtime_dependency "nokogiri"
21
+ s.add_runtime_dependency "nokogiri", "~> 1.4"
24
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oeis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,30 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-17 00:00:00.000000000Z
12
+ date: 2012-02-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70205976074160 !ruby/object:Gem::Requirement
16
+ requirement: &70156756845880 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: *70205976074160
25
- - !ruby/object:Gem::Dependency
26
- name: nokogiri
27
- requirement: &70205976073680 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
21
+ version: '1.4'
33
22
  type: :runtime
34
23
  prerelease: false
35
- version_requirements: *70205976073680
24
+ version_requirements: *70156756845880
36
25
  description: Allows you to fetch results from OEIS using a list of integers
37
26
  email:
38
27
  - scalesjordan@gmail.com
@@ -44,6 +33,7 @@ files:
44
33
  - Gemfile
45
34
  - README.md
46
35
  - Rakefile
36
+ - examples/thue-morse.rb
47
37
  - lib/oeis.rb
48
38
  - lib/oeis/version.rb
49
39
  - oeis.gemspec