oeis 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +4 -3
  2. data/lib/oeis/version.rb +1 -1
  3. data/lib/oeis.rb +20 -7
  4. metadata +5 -5
data/README.md CHANGED
@@ -9,8 +9,9 @@ input.
9
9
  ## Usage
10
10
 
11
11
  > require 'oeis'
12
- > l = 3.upto(10).collect { |i| i*i }
13
- > result = OEIS::Search(l)
12
+ > ls = 3.upto(10).collect { |i| i*i }
13
+ [9, 16, 25, 36, 49, 64, 81, 100]
14
+ > result = OEIS::search(ls)
14
15
 
15
16
  > p result.title
16
17
  The squares: a(n) = n^2.
@@ -25,7 +26,7 @@ input.
25
26
  cd oeis
26
27
  bundle
27
28
  gem build oeis.gemspec
28
- gem install oeis-0.0.1
29
+ gem install oeis-X.X.X.gem
29
30
 
30
31
  **OR**
31
32
 
data/lib/oeis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oeis
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/oeis.rb CHANGED
@@ -4,29 +4,42 @@ require 'open-uri'
4
4
 
5
5
  module OEIS
6
6
  # Your code goes here...
7
- class OEIS
7
+ class OEISParser
8
8
 
9
9
  BASE_URL = 'http://oeis.org/search?q='
10
10
 
11
11
  attr_accessor :id, :title, :sequence
12
12
 
13
- def initialize(l)
14
- url = BASE_URL + l.join(',')
15
- doc = Nokogiri::HTML(open(url))
13
+ def initialize(ls)
14
+ 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
16
20
 
17
21
  first_result = doc.css('table table:eq(2)').first
18
22
  info = first_result.css('tr:eq(3) table > tr > td > a').first
19
23
 
24
+ if info.nil?
25
+ puts 'No sequence found.'
26
+ return nil
27
+ end
28
+
20
29
  @id = info.attributes['href'].value[1..-1]
21
30
  @title = info.attributes['title'].value
22
31
 
23
32
  digits = first_result.css('tr:eq(4) table tr tt').text.split(', ')
24
- @sequence = digits.map { |a| a.to_i }
33
+ @sequence = digits.map &:to_i
34
+ end
35
+
36
+ def to_s
37
+ "#{@id}: #{@title}"
25
38
  end
26
39
 
27
40
  end
28
41
 
29
- def self.Search(l)
30
- OEIS.new(l)
42
+ def self.search(ls)
43
+ OEISParser.new(ls)
31
44
  end
32
45
  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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70362600493200 !ruby/object:Gem::Requirement
16
+ requirement: &70205976074160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70362600493200
24
+ version_requirements: *70205976074160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &70362600492780 !ruby/object:Gem::Requirement
27
+ requirement: &70205976073680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70362600492780
35
+ version_requirements: *70205976073680
36
36
  description: Allows you to fetch results from OEIS using a list of integers
37
37
  email:
38
38
  - scalesjordan@gmail.com