rice-dining 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ba72d909940c766ae7986376076eff2a7e86e4a
4
- data.tar.gz: 4d8a502c61a2d191bdbe46edbdb0ef5c315e2106
3
+ metadata.gz: 053c8958f2d51a5126a1e35eecda8feb8c87e0f8
4
+ data.tar.gz: 677740468a8bc2000ae5e440b8ba9621a3353791
5
5
  SHA512:
6
- metadata.gz: a36d5b22138fe1ee7bc87b0c08ea6d893cf72e9d4e92a968ed1f295e756815d54926a8118f96a29eeb5fd349dee236a5844ac14316b946723898848a68a92a5d
7
- data.tar.gz: 97e05d13092ea66bb6f0a942d2d71550cdea48ea37b89bf0273e75c38ca0f5e0e2aebab94a9ae8ecc9ee6d7d36039998c916a4092b87a754bb8f747cad9ec68a
6
+ metadata.gz: 51a9af6fd340a2bbae2485a6eed03a1f2af4a101645a61fc80ae47c2a808ec25824a298c7e16173d5a4175457439397e4f89b3870e8c9dbe82c9613c6a33cfb9
7
+ data.tar.gz: 558a8a1e61bb1d5f6a5bc10b110edf08ec198db9efed91b300227513aa50a1b55851b4948aaaa51dbfd3eeb6af68dea50ce28ae0b319c8656559d56f56d90da9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rice-dining (0.2.1)
4
+ rice-dining (0.2.2)
5
5
  colorize (~> 0.7)
6
6
  nokogiri (~> 1.6)
7
7
 
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
@@ -43,6 +43,7 @@ begin
43
43
  }
44
44
  printed = 0
45
45
 
46
+ STDOUT.puts "#{manifest.title.white} (as of #{Time.now})"
46
47
  manifest.locations.each do |location|
47
48
  next unless location.name =~ regex
48
49
  STDOUT.print "#{location.name}: "
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
- raise ArgumentError unless locations.is_a? Enumerable and allergens.is_a? Enumerable
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}"
@@ -1,7 +1,7 @@
1
1
  module Rice
2
2
  module Dining
3
3
  module Version
4
- VERSION = '0.2.2'.freeze
4
+ VERSION = '0.2.3'.freeze
5
5
  SHORT_NAME = Rice::Dining.to_s.freeze
6
6
  SHORT_IDENT = "#{SHORT_NAME} v#{VERSION}".freeze
7
7
  NAME = SHORT_NAME.freeze
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rice-dining
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morgan Jones