rice-dining 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +27 -1
- data/bin/rice-dining +1 -0
- data/lib/rice/dining.rb +23 -5
- data/lib/rice/dining/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 053c8958f2d51a5126a1e35eecda8feb8c87e0f8
|
4
|
+
data.tar.gz: 677740468a8bc2000ae5e440b8ba9621a3353791
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51a9af6fd340a2bbae2485a6eed03a1f2af4a101645a61fc80ae47c2a808ec25824a298c7e16173d5a4175457439397e4f89b3870e8c9dbe82c9613c6a33cfb9
|
7
|
+
data.tar.gz: 558a8a1e61bb1d5f6a5bc10b110edf08ec198db9efed91b300227513aa50a1b55851b4948aaaa51dbfd3eeb6af68dea50ce28ae0b319c8656559d56f56d90da9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -9,9 +9,35 @@ Provides a `rice-dining` executable that prints servery offerings at Rice.
|
|
9
9
|
## Invocation
|
10
10
|
|
11
11
|
Run `rice-dining` to print status for everything, or `rice-dining <regex>` to print status
|
12
|
-
for locations matching `<regex
|
12
|
+
for locations matching `<regex>`.
|
13
|
+
|
14
|
+
For example, `rice-dining 'baker|seibel'` would display information for the Baker and
|
15
|
+
Seibel serveries.
|
13
16
|
|
14
17
|
## Screenshot
|
15
18
|
|
16
19
|
![Screenshot](/png/screenshot.png?raw=true)
|
17
20
|
|
21
|
+
## Class hierarchy
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Rice::Dining::Manifest {
|
25
|
+
locations: [Rice::Dining::Location, ...], # Array
|
26
|
+
allergens: [Rice::Dining::Allergen, ...] # Set
|
27
|
+
}
|
28
|
+
|
29
|
+
Rice::Dining::Location {
|
30
|
+
name: String,
|
31
|
+
items: [Rice::Dining::Item, ...] # Array
|
32
|
+
}
|
33
|
+
|
34
|
+
Rice::Dining::Item {
|
35
|
+
name: String,
|
36
|
+
allergens: [Rice::Dining::Allergen, ...] # Set
|
37
|
+
}
|
38
|
+
|
39
|
+
Rice::Dining::Allergen {
|
40
|
+
id: Symbol,
|
41
|
+
shortcode: Symbol
|
42
|
+
}
|
43
|
+
```
|
data/bin/rice-dining
CHANGED
data/lib/rice/dining.rb
CHANGED
@@ -10,9 +10,11 @@ module Rice
|
|
10
10
|
BASE = URI('http://dining.rice.edu').freeze
|
11
11
|
|
12
12
|
class Manifest
|
13
|
-
attr_reader :locations, :allergens
|
14
|
-
def initialize locations, allergens
|
15
|
-
|
13
|
+
attr_reader :title, :locations, :allergens
|
14
|
+
def initialize title, locations, allergens
|
15
|
+
title = title ? title.dup.freeze : 'Dining'.freeze
|
16
|
+
raise ArgumentError unless title.is_a? String and locations.is_a? Enumerable and allergens.is_a? Enumerable
|
17
|
+
@title = title
|
16
18
|
@locations, @allergens = [], Set.new
|
17
19
|
locations.each do |location|
|
18
20
|
raise ArgumentError unless location.is_a?(Rice::Dining::Location)
|
@@ -40,8 +42,8 @@ module Rice
|
|
40
42
|
raise ArgumentError unless item.is_a?(Rice::Dining::Item)
|
41
43
|
@items << item
|
42
44
|
end
|
43
|
-
|
44
45
|
@items.freeze
|
46
|
+
|
45
47
|
self.freeze
|
46
48
|
end
|
47
49
|
|
@@ -65,6 +67,7 @@ module Rice
|
|
65
67
|
@allergens << allergen
|
66
68
|
end
|
67
69
|
@allergens.freeze
|
70
|
+
|
68
71
|
self.freeze
|
69
72
|
end
|
70
73
|
end
|
@@ -113,6 +116,21 @@ module Rice
|
|
113
116
|
if res.is_a? Net::HTTPSuccess
|
114
117
|
doc = Nokogiri::HTML(res.body)
|
115
118
|
|
119
|
+
# find the title
|
120
|
+
title_nodes = doc.css('div.alpha h1:contains("Your")'.freeze)
|
121
|
+
unless title_nodes.empty?
|
122
|
+
title_stuff = title_nodes.first.text
|
123
|
+
title_stuff.strip!
|
124
|
+
title_match = title_stuff.match /\Ayour\s+(?<title>[a-z]+)/i
|
125
|
+
if title_match
|
126
|
+
title = title_match[:title]
|
127
|
+
else
|
128
|
+
title = nil
|
129
|
+
end
|
130
|
+
else
|
131
|
+
title = nil
|
132
|
+
end
|
133
|
+
|
116
134
|
# stash allergen references in the "key" section
|
117
135
|
doc.css('div#key div.diet'.freeze).each do |allergen_node|
|
118
136
|
allergen_reference allergen_node['class'.freeze]
|
@@ -162,7 +180,7 @@ module Rice
|
|
162
180
|
end
|
163
181
|
end
|
164
182
|
|
165
|
-
Rice::Dining::Manifest.new locations, @allergen_map.values
|
183
|
+
Rice::Dining::Manifest.new title, locations, @allergen_map.values
|
166
184
|
else
|
167
185
|
# Problem with the response
|
168
186
|
raise CreateError, "got HTTP #{res.code} from #{Rice::Dining::BASE}"
|
data/lib/rice/dining/version.rb
CHANGED