eaternet 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c214305218f45f7fc0f0110e0a20262dc89c1b3
4
- data.tar.gz: b3713a441f427f7157999e8152e82a36bc6ac30c
3
+ metadata.gz: af617767abcfabf9ef5d9db64481d40ff6a4c174
4
+ data.tar.gz: 157ecfe72159f0bf69fce1482d584d06eec42223
5
5
  SHA512:
6
- metadata.gz: ace2d1b0f63390feee961ccdabede4f35792d746003726ba676d28f571ca18de77510a11e5f937e2f0f693297280eb2cb9cb3c58974a96bb7047d3e7145bff79
7
- data.tar.gz: defe8a3e5cf85ccf3788e6fcb7a298a5e39261eb839b6834ab01f0cda797302926ca89435da362106b44a7e54c5527c9e369877e853e81ee2666fed2504ff7fe
6
+ metadata.gz: 209c90a1a9bd7e0524dc114624dcaf5ef90af0e26d98582797b80b83702d2fc34cd10b567a7a210dc8b147175566188b6468d52cdd0901d68036db88aed4c772
7
+ data.tar.gz: cf63bcaf4d071b8f13b9135b26aa2d92eb2cbf93118a340666f9749af5a36b39c9495b6915c0612dc1a72ea12305bf1bcd7642a49e56d630727547f0ca8ec187
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1
4
- - 2.2
4
+ - 2.2.1
5
+ - 2.2.2
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in eaternet-adapters.gemspec
3
+ gem 'minitest-utils', git: 'git@github.com:dogweather/minitest-utils.git'
4
4
  gemspec
data/eaternet.gemspec CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'guard'
24
24
  spec.add_development_dependency 'guard-minitest'
25
25
  spec.add_development_dependency 'minitest'
26
- spec.add_development_dependency 'minitest-utils'
27
26
  spec.add_development_dependency 'pry'
28
27
  spec.add_development_dependency 'rake', '~> 10'
29
28
  spec.add_development_dependency 'vcr'
@@ -4,62 +4,62 @@ module Eaternet
4
4
  module Lives_1_0
5
5
  # Information about an inspectors’ visit to a businesses.
6
6
  #
7
- # @todo Clean up the Yard doc.
8
7
  # @see http://www.yelp.com/healthscores#inspections LIVES / Inspections
9
8
  # specification
10
9
  class Inspection < ValidatedObject
11
10
  ZERO_TO_ONE_HUNDRED_AND_BLANK = (0..100).to_a + ['']
12
11
 
13
12
  # Unique identifier of the business for which this inspection
14
- # was done. Required.
13
+ # was done.
15
14
  #
15
+ # @required Yes
16
16
  # @return [String]
17
17
  attr_accessor :business_id
18
- validates :business_id,
19
- type: String,
20
- presence: true
18
+ validates :business_id, type: String, presence: true
21
19
 
22
- # @!attribute [rw] score
23
- # Inspection score on a 0-100 scale. 100 is the highest score.
24
- # This column must always be present in inspections.csv. However, it
25
- # can be safely left blank for inspection rows that don’t have an
26
- # associated score. (For example, some municipalities don’t associate
27
- # a follow-up inspection with a score.)
28
- # @return [Integer] if it's a scored inspection
29
- # @return [String] if it's an un-scored inspection, then the return
30
- # value will be an empty string.
20
+ # Inspection score on a 0-100 scale. 100 is the highest score. This
21
+ # column must always be present in inspections.csv. However, it can be
22
+ # safely left blank for inspection rows that don’t have an associated
23
+ # score. (For example, some municipalities don’t associate a follow-up
24
+ # inspection with a score.)
25
+ #
26
+ # @required No
27
+ # @return [Integer] if it's a scored inspection
28
+ # @return [String] if it's an un-scored inspection, then the return
29
+ # value will be an empty string.
31
30
  attr_accessor :score
32
- validates :score,
33
- inclusion: { in: ZERO_TO_ONE_HUNDRED_AND_BLANK },
34
- allow_nil: true
31
+ validates :score,
32
+ inclusion: { in: ZERO_TO_ONE_HUNDRED_AND_BLANK },
33
+ allow_nil: true
35
34
  def score
36
35
  # noinspection RubyResolve
37
36
  @score.nil? ? '' : @score
38
37
  end
39
38
 
40
- # @!attribute [rw] date
41
- # Date of the inspection.
42
- # @return [Date]
39
+ # Date of the inspection.
40
+ #
41
+ # @required Yes
42
+ # @return [Date]
43
43
  attr_accessor :date
44
- validates :date,
45
- type: Date,
46
- presence: true
44
+ validates :date, type: Date, presence: true
47
45
 
48
- # @!attribute [rw] description
49
- # Single line description containing details on the outcome of an
50
- # inspection. Use of this field is only encouraged if no violations
51
- # are provided.
52
- # @return [String]
46
+ # Single line description containing details on the outcome of an
47
+ # inspection. Use of this field is only encouraged if no violations
48
+ # are provided.
49
+ #
50
+ # @required No
51
+ # @return [String]
53
52
  attr_accessor :description
54
53
 
55
- # @!attribute [rw] type
56
- # String representing the type of inspection. Must be (initial,
57
- # routine, followup, complaint).
58
- # @return [String]
54
+ # String representing the type of inspection. Must be (initial,
55
+ # routine, followup, complaint).
56
+ #
57
+ # @required No
58
+ # @return [String]
59
59
  attr_accessor :type
60
- validates :type,
61
- inclusion: { in: %w(initial routine followup complaint) },
62
- allow_nil: true
60
+ validates :type,
61
+ inclusion: { in: %w(initial routine followup complaint) },
62
+ allow_nil: true
63
63
 
64
64
  # @return [String]
65
65
  def to_s
@@ -2,19 +2,47 @@ require 'eaternet/validated_object'
2
2
 
3
3
  module Eaternet
4
4
  module Lives_1_0
5
- # @todo Document
5
+ # Contains information about specific violations.
6
+ #
7
+ # @required No
6
8
  # @see http://www.yelp.com/healthscores#violations LIVES / Violations
7
9
  # specification
8
10
  class Violation < ValidatedObject
9
- attr_accessor :business_id, :date, :code, :description
10
-
11
+ # Unique identifier of the business for which this violation applies
12
+ #
13
+ # @required Yes
14
+ # @return [String]
15
+ attr_accessor :business_id
11
16
  validates :business_id,
12
17
  type: String,
13
18
  presence: true
19
+
20
+ # Date of violation. This should correspond with the related inspection.
21
+ #
22
+ # @required Yes
23
+ # @return [Date]
24
+ attr_accessor :date
14
25
  validates :date,
15
26
  type: Date,
16
27
  presence: true
17
- validates :code, :description,
28
+
29
+ # Code for the violation. It is recommended that this be based on the FDA
30
+ # Food Code. However, municipalities can decide to use pre-existing codes
31
+ # for this field.
32
+ #
33
+ # @required No
34
+ # @return [String]
35
+ attr_accessor :code
36
+ validates :code,
37
+ type: String,
38
+ allow_nil: true
39
+
40
+ # One line description of the violation.
41
+ #
42
+ # @required No
43
+ # @return [String]
44
+ attr_accessor :description
45
+ validates :description,
18
46
  type: String,
19
47
  allow_nil: true
20
48
  end
@@ -5,8 +5,8 @@ module Eaternet
5
5
  # to create custom validating objects.
6
6
  #
7
7
  # Uses [ActiveModel::Validations](http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates)
8
- # to create self-validating Plain Old Ruby objects. This is especially useful for
9
- # data validation when importing from CSV.
8
+ # to create self-validating Plain Old Ruby objects. This is especially
9
+ # useful for data validation when importing from CSV.
10
10
  #
11
11
  # @example Writing a self-validating object
12
12
  # class Dog < Eaternet::ValidatedObject
@@ -17,8 +17,8 @@ module Eaternet
17
17
  # end
18
18
  #
19
19
  # @example Instantiating and automatically validating
20
- # # The dog1 instance is validated at the end of instantiation. Here, it succeeds
21
- # # without exception.
20
+ # # The dog1 instance is validated at the end of instantiation.
21
+ # # Here, it succeeds without exception.
22
22
  # dog1 = Dog.new do |d|
23
23
  # d.name = 'Spot'
24
24
  # end
@@ -55,11 +55,12 @@ module Eaternet
55
55
  # Run any validations and raise an error if invalid.
56
56
  # @raise [ArgumentError] if any validations fail.
57
57
  def check_validations!
58
- fail ArgumentError, errors.messages.inspect if invalid?
58
+ fail ArgumentError, errors.full_messages.join('; ') if invalid?
59
59
  end
60
60
 
61
61
  # A custom validator which ensures an object is a certain class.
62
- # It's here as a nested class in {ValidatedObject} for easy access by subclasses.
62
+ # It's here as a nested class in {ValidatedObject} for easy
63
+ # access by subclasses.
63
64
  #
64
65
  # @example Ensure that weight is a floating point number
65
66
  # class Dog < ValidatedObject
@@ -69,10 +70,12 @@ module Eaternet
69
70
  class TypeValidator < ActiveModel::EachValidator
70
71
  # @return [nil]
71
72
  def validate_each(record, attribute, value)
72
- return if value.class == options[:with]
73
+ expected = options[:with]
74
+ actual = value.class
75
+ return if actual == expected
73
76
 
74
- message = options[:message] || "is not of class #{options[:with]}"
75
- record.errors.add attribute, message
77
+ msg = options[:message] || "is class #{actual}, not #{expected}"
78
+ record.errors.add attribute, msg
76
79
  end
77
80
  end
78
81
  end
@@ -1,3 +1,3 @@
1
1
  module Eaternet
2
- VERSION = '0.3.5'
2
+ VERSION = '0.3.6'
3
3
  end
@@ -9,7 +9,7 @@ class BusinessTest < Minitest::Test
9
9
 
10
10
  PORTLAND_OR_US = { lat: 45.5236111, lon: -122.675 }
11
11
 
12
- def test_business_without_lat_and_lon
12
+ def test_creates_business_without_lat_and_lon
13
13
  business = Eaternet::Lives_1_0::Business.new do |i|
14
14
  i.business_id = '789123hjd'
15
15
  i.name = 'Starbucks'
@@ -18,7 +18,7 @@ class BusinessTest < Minitest::Test
18
18
  refute_nil business
19
19
  end
20
20
 
21
- def test_business_rejects_lat_and_lon_which_are_not_numbers
21
+ def test_rejects_lat_and_lon_which_are_not_numbers
22
22
  assert_raises(ArgumentError) {
23
23
  Eaternet::Lives_1_0::Business.new do |i|
24
24
  i.business_id = '789123hjd'
@@ -30,7 +30,7 @@ class BusinessTest < Minitest::Test
30
30
  }
31
31
  end
32
32
 
33
- def test_business_with_lat_and_lon
33
+ def test_creates_business_with_lat_and_lon
34
34
  business = Eaternet::Lives_1_0::Business.new do |i|
35
35
  i.business_id = '789123hjd'
36
36
  i.name = 'Starbucks'
@@ -41,7 +41,7 @@ class BusinessTest < Minitest::Test
41
41
  refute_nil business
42
42
  end
43
43
 
44
- def test_business_rejects_invalid_latitude
44
+ def test_rejects_invalid_latitude
45
45
  assert_raises(ArgumentError) {
46
46
  Eaternet::Lives_1_0::Business.new do |i|
47
47
  i.business_id = '789123hjd'
@@ -53,7 +53,7 @@ class BusinessTest < Minitest::Test
53
53
  }
54
54
  end
55
55
 
56
- def test_business_rejects_invalid_longitude
56
+ def test_rejects_invalid_longitude
57
57
  assert_raises(ArgumentError) {
58
58
  Eaternet::Lives_1_0::Business.new do |i|
59
59
  i.business_id = '789123hjd'
@@ -69,7 +69,7 @@ class BusinessTest < Minitest::Test
69
69
  # Business#name
70
70
  #
71
71
 
72
- def test_business_rejects_blank_name
72
+ def test_rejects_blank_name
73
73
  assert_raises(ArgumentError) {
74
74
  Eaternet::Lives_1_0::Business.new do |i|
75
75
  i.business_id = '789123hjd'
data/test/script.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'date'
2
+ require 'eaternet/validated_object'
3
+
4
+ # @example Writing a self-validating object
5
+ # class Dog < Eaternet::ValidatedObject
6
+ # attr_accessor :name, :birthday
7
+ #
8
+ # validates :name, presence: true
9
+ # validates :birthday, type: Date, allow_nil: true
10
+ # end
11
+ #
12
+ # @example Instantiating and automatically validating
13
+ # # The dog1 instance is validated at the end of instantiation.
14
+ # # Here, it succeeds without exception.
15
+ # dog1 = Dog.new do |d|
16
+ # d.name = 'Spot'
17
+ # end
18
+ #
19
+ # # We can also explicitly test for validity
20
+ # dog1.valid? # => true
21
+ #
22
+ # dog1.birthday = Date.new(2015, 1, 23)
23
+ # dog1.valid? # => true
24
+ #
25
+ # @example Making an instance invalid
26
+ # dog1.birthday = '2015-01-23'
27
+ # dog1.valid? # => false
28
+ # dog1.check_validations! # => ArgumentError: birthday is not of class Date
29
+
30
+ class Dog < Eaternet::ValidatedObject
31
+ attr_accessor :name, :birthday
32
+
33
+ validates :name, presence: true
34
+ validates :birthday, type: Date, allow_nil: true
35
+ end
36
+
37
+ dog1 = Dog.new do |d|
38
+ d.name = 'Spot'
39
+ end
40
+ puts "dog1.valid? #{dog1.valid?}"
41
+
42
+ dog1.birthday = '2015-01-23'
43
+ dog1.check_validations!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eaternet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: minitest-utils
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: pry
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -209,6 +195,7 @@ files:
209
195
  - test/eaternet/nyc_adapter_test.rb
210
196
  - test/eaternet/snhd_adapter_test.rb
211
197
  - test/fixtures/morris-park-bake-shop.csv
198
+ - test/script.rb
212
199
  - test/test_helper.rb
213
200
  homepage: https://github.com/eaternet/adapters-ruby
214
201
  licenses:
@@ -230,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
217
  version: '0'
231
218
  requirements: []
232
219
  rubyforge_project:
233
- rubygems_version: 2.4.6
220
+ rubygems_version: 2.4.7
234
221
  signing_key:
235
222
  specification_version: 4
236
223
  summary: Regional adapters for restaurant health scores
@@ -244,5 +231,6 @@ test_files:
244
231
  - test/eaternet/nyc_adapter_test.rb
245
232
  - test/eaternet/snhd_adapter_test.rb
246
233
  - test/fixtures/morris-park-bake-shop.csv
234
+ - test/script.rb
247
235
  - test/test_helper.rb
248
236
  has_rdoc: