weather_funds 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in weather_lottery.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kieran Johnson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # WeatherFunds
2
+
3
+ Ruby interface to lottery results from http://weatherfunds.co.uk
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'weather_funds'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install weather_funds
18
+
19
+ ## Usage
20
+
21
+ require 'weather_funds'
22
+
23
+ # Sunshine and Lightning are both supported
24
+ sunshine = WeatherFunds::Sunshine.new
25
+
26
+ # Find your lottery
27
+ lottery = sunshine.find(name)
28
+ # Or find by scheme idenifier
29
+ lottery = sunshine.find_by_scheme(scheme)
30
+
31
+ # Get the results. Returns array of date and data
32
+ sunshine.results
33
+
34
+ # Get the winners for your lottery. Returns name and prize amount
35
+ lottery.winners
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ module WeatherFunds
2
+
3
+ class Lightning < ResultSet
4
+
5
+ def initialize
6
+ super('lreslt', 'schl')
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,24 @@
1
+ module WeatherFunds
2
+
3
+ class Lottery
4
+
5
+ Winner = Struct.new(:name, :prize)
6
+
7
+ attr_reader :name, :scheme
8
+
9
+ def initialize(name, scheme)
10
+ @name, @scheme = name, scheme
11
+ @winners = []
12
+ end
13
+
14
+ def winners
15
+ @winners
16
+ end
17
+
18
+ def <<(winner)
19
+ @winners << winner
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,61 @@
1
+ module WeatherFunds
2
+
3
+ class ResultSet
4
+
5
+ Result = Struct.new(:date, :data)
6
+
7
+ def initialize(result_tag, winner_tag)
8
+ @result_tag = result_tag
9
+ @winner_tag = winner_tag
10
+ @data = Nokogiri::XML(open("http://weatherfunds.co.uk/windata.xml"))
11
+ end
12
+
13
+ def date
14
+ @data.css('wl').first['wdate']
15
+ end
16
+
17
+ def results
18
+ @results ||= extract_results
19
+ end
20
+
21
+ def lotteries
22
+ @lotteries ||= extract_winners
23
+ end
24
+
25
+ def find(name)
26
+ @lotteries.select { |lottery| lottery.name == name }[0]
27
+ end
28
+
29
+ def find_by_scheme(scheme)
30
+ @lotteries.select { |lottery| lottery.scheme == scheme }[0]
31
+ end
32
+
33
+ private
34
+
35
+ def extract_winners
36
+ @data.css("#{@winner_tag}").inject([]) do |result, res|
37
+ lottery = Lottery.new(res['name'], res['scheme'])
38
+
39
+ res.search('wn').each do |winner|
40
+ lottery << Lottery::Winner.new(winner.search('n').text, winner.search('pr').text)
41
+ end
42
+
43
+ result << lottery
44
+ result
45
+ end
46
+ end
47
+
48
+ def extract_results
49
+ @data.css("#{@result_tag} res").inject([]) do |result, res|
50
+ date = Date.parse(res["idate"])
51
+ data = res.search('d').map { |i| i.text.to_i }
52
+ tmp = Result.new(date, data)
53
+
54
+ result << tmp
55
+ result
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,11 @@
1
+ module WeatherFunds
2
+
3
+ class Sunshine < ResultSet
4
+
5
+ def initialize
6
+ super('sreslt', 'sch')
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,3 @@
1
+ module WeatherFunds
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "open-uri"
2
+ require "nokogiri"
3
+
4
+ require "weather_funds/version"
5
+ require "weather_funds/result_set"
6
+ require "weather_funds/lottery"
7
+ require "weather_funds/sunshine"
8
+ require "weather_funds/lightning"
9
+
10
+ module WeatherFunds
11
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'weather_funds/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "weather_funds"
8
+ gem.version = WeatherFunds::VERSION
9
+ gem.authors = ["Kieran Johnson"]
10
+ gem.email = ["kieran@invisiblelines.com"]
11
+ gem.description = %q{Ruby interface to results from weatherfunds.co.uk}
12
+ gem.summary = %q{Ruby interface to results from weatherfunds.co.uk}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "nokogiri"
21
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_funds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kieran Johnson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &70234560282240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70234560282240
25
+ description: Ruby interface to results from weatherfunds.co.uk
26
+ email:
27
+ - kieran@invisiblelines.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - lib/weather_funds.rb
38
+ - lib/weather_funds/lightning.rb
39
+ - lib/weather_funds/lottery.rb
40
+ - lib/weather_funds/result_set.rb
41
+ - lib/weather_funds/sunshine.rb
42
+ - lib/weather_funds/version.rb
43
+ - weather_funds.gemspec
44
+ homepage: ''
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.11
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Ruby interface to results from weatherfunds.co.uk
68
+ test_files: []