the_community_farm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8a1bfb7a05011f162483225610abcfa1b94708cd
4
+ data.tar.gz: 69aede8fc1542cec07ce9d8af80c9d82470f8064
5
+ SHA512:
6
+ metadata.gz: 0734cc0d8ab0a35c474e20fdeb3d76c01286bacb7e490ea6bf435402635bd6f32b5a2e6239be02cf3715015aaf11e04116f96e8863b2a4ddd23d21d937a2b15d
7
+ data.tar.gz: 96af024fea259a53604e7dbc907f2b32e8fc08d441c45ed4c3091f38a560d5ed9143320a985c355ebac541bd1099ad82dc4e9635a8b622827e3b18d02ee91672
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3.1
8
+ before_install: gem install bundler -v 1.13.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## [0.1.0](https://github.com/chrismytton/the_community_farm/tag/v0.1.0) 2016-10-01
9
+
10
+ ### Added
11
+
12
+ - Basic interface for accessing the contents of the farm's organic veg boxes.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in the_community_farm.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Chris Mytton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # TheCommunityFarm
2
+
3
+ This RubyGem provides a way to access the contents of various veg boxes from [The Community Farm](https://www.thecommunityfarm.co.uk/) in your Ruby programs. I use it to generate an XML feed of the various boxes which I can then plug into an IFTTT recipe which emails me when the weekly box contents is updated.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'the_community_farm'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install the_community_farm
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'the_community_farm'
25
+ require 'open-uri'
26
+
27
+ organic_boxes = TheCommunityFarm::OrganicBoxes.new(html: open('https://www.thecommunityfarm.co.uk/boxes/box_display.php').read)
28
+
29
+ organic_boxes.each do |box|
30
+ puts box
31
+ puts
32
+ box.items.each { |item| puts "- #{item}" }
33
+ puts
34
+ end
35
+ ```
36
+
37
+ Which will output:
38
+
39
+ ```
40
+ All For One
41
+
42
+ - Potatoes (Valor) (Somerset)
43
+ - Carrots (Dirty) (Somerset)
44
+ - Cauliflower (Green) (Somerset)
45
+ - Cabbage (Pointed) (Cornwall)
46
+ - Leeks (Our Field)
47
+ - Sweetcorn (Somerset)
48
+ - Chillies (Our Field)
49
+
50
+ Family Provider Large
51
+
52
+ - Potatoes (Valor) (Somerset)
53
+ - Carrots (Dirty) (Somerset)
54
+ - Parsnips (Somerset)
55
+ - Cauliflower (Green) (Somerset)
56
+ - Brussel Sprout Tops (Somerset)
57
+ - Cabbage (White) (Our Field)
58
+ - Butternut Squash (Somerset)
59
+ - Leeks (our field)
60
+ - Sweetcorn (Somerset)
61
+ - Beetroot (Somerset)
62
+ - Apples (Hereford)
63
+ - Bananas (Ecuador)
64
+ - Oranges (SPA)
65
+
66
+ Family Provider Small
67
+
68
+ - Potatoes (Valor) (Somerset)
69
+ - Carrots (Dirty) (Somerset)
70
+ - Parsnips (Somerset)
71
+ - Cauliflower (Green) (Somerset)
72
+ - Leeks (our field)
73
+ - Sweetcorn (Somerset)
74
+ - Onions (Somerset)
75
+ - Chard (Rainbow) (Our Field)
76
+ - Chillies (Our field)
77
+ - Apples (Hereford)
78
+ - Bananas (Ecuador)
79
+ - Oranges (SPA)
80
+
81
+ [snip]
82
+ ```
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chrismytton/the_community_farm.
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ require 'rubocop/rake_task'
11
+ RuboCop::RakeTask.new
12
+
13
+ task default: %i(test rubocop)
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'the_community_farm'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/example.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'the_community_farm'
2
+ require 'open-uri'
3
+
4
+ organic_boxes = TheCommunityFarm::OrganicBoxes.new(html: open('https://www.thecommunityfarm.co.uk/boxes/box_display.php').read)
5
+
6
+ organic_boxes.each do |box|
7
+ puts box
8
+ puts
9
+ box.items.each { |item| puts "- #{item}" }
10
+ puts
11
+ end
@@ -0,0 +1,50 @@
1
+ require 'digest'
2
+
3
+ module TheCommunityFarm
4
+ class OrganicBoxes
5
+ # Represents a single organic veg box.
6
+ class Box
7
+ def initialize(noko:)
8
+ @noko = noko
9
+ end
10
+
11
+ def id
12
+ Digest::MD5.new.tap do |id|
13
+ id.update(title)
14
+ id.update(items.join("\n"))
15
+ end.hexdigest
16
+ end
17
+
18
+ def title
19
+ @title ||= noko.at_css('.lead').text.strip
20
+ end
21
+
22
+ def box_size
23
+ @box_size ||= begin
24
+ size = noko.at_css('option[selected]')
25
+ size && size.text && size.text.strip
26
+ end
27
+ end
28
+
29
+ def items
30
+ @items ||= item_doc.css('li').map { |li| li.text.strip }
31
+ end
32
+
33
+ def to_s
34
+ "#{title} #{box_size}".strip
35
+ end
36
+
37
+ private
38
+
39
+ attr_reader :noko
40
+
41
+ def item_doc
42
+ @item_doc ||= Nokogiri::HTML(noko.at_css(item_selector)['data-content'])
43
+ end
44
+
45
+ def item_selector
46
+ %([data-content*="This week's contents"])
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,29 @@
1
+ require 'nokogiri'
2
+ require 'the_community_farm/organic_boxes/box'
3
+
4
+ module TheCommunityFarm
5
+ # Represents a list of organic veg boxes.
6
+ class OrganicBoxes
7
+ include Enumerable
8
+
9
+ def initialize(html:)
10
+ @html = html
11
+ end
12
+
13
+ def each(&block)
14
+ boxes.each(&block)
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :html
20
+
21
+ def boxes
22
+ noko.css('.panel').map { |p| Box.new(noko: p) }
23
+ end
24
+
25
+ def noko
26
+ @noko ||= Nokogiri::HTML(html)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module TheCommunityFarm
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'the_community_farm/version'
2
+ require 'the_community_farm/organic_boxes'
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_community_farm/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'the_community_farm'
8
+ spec.version = TheCommunityFarm::VERSION
9
+ spec.authors = ['Chris Mytton']
10
+ spec.email = ['chrismytton@gmail.com']
11
+
12
+ spec.summary = 'Unofficial API for The Community Farm Bristol'
13
+ spec.homepage = 'https://github.com/chrismytton/the_community_farm'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.13'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'minitest', '~> 5.0'
28
+ spec.add_development_dependency 'pry', '~> 0.10'
29
+ spec.add_development_dependency 'rubocop', '~> 0.43'
30
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_community_farm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Mytton
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.43'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.43'
97
+ description:
98
+ email:
99
+ - chrismytton@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".travis.yml"
107
+ - CHANGELOG.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - example.rb
115
+ - lib/the_community_farm.rb
116
+ - lib/the_community_farm/organic_boxes.rb
117
+ - lib/the_community_farm/organic_boxes/box.rb
118
+ - lib/the_community_farm/version.rb
119
+ - the_community_farm.gemspec
120
+ homepage: https://github.com/chrismytton/the_community_farm
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.5.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Unofficial API for The Community Farm Bristol
144
+ test_files: []