eaternet 0.4.3 → 0.4.4

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: 9f09792a0e3e7fe94b6c3379288c8e49093792f2
4
- data.tar.gz: 4aa2df5d05299c963e82f774540cad1f54d5a0c3
3
+ metadata.gz: d229e39d8e34a1c791ce2d212de62da1e1001ca3
4
+ data.tar.gz: c8f41c3455bcdbacca49900fd6691acae380d689
5
5
  SHA512:
6
- metadata.gz: 0c7e7427fc67460dcca75658313f734534574dd77fb40fdadd94e73bf6d0be4425b44daf82233004d217b1cac11e123b2c798c56e1c8b3a1c58f07e3ac60b2e4
7
- data.tar.gz: 87a118b0c3a3ce819f81b92c94b645ed413a09d89982468248d308e61b6f842d679e961cbf71c2fcdfcf364f3717a81f3fdf76f050b6091d398d5c112ef36090
6
+ metadata.gz: fe5fd0d5c67daeb5c173315e7f6e9bf01e903b6455995e0bdfddd61524e3630b9f5ac5b0e383d570825e5b1a2e62f241242eff877e200ef62ef6c4c629273392
7
+ data.tar.gz: 8a491c8d04d2022c1d75e34c2e196e070f6289c28bbb52514570cfc88eac9f5fdf4ef647ccd066b394870f72b45a5d5f26d9333e7edc4c826428843d3f9cb311
@@ -67,7 +67,7 @@ module Eaternet
67
67
  # @return [String] the cleaned up string
68
68
  def self.cleanup_title(a_string)
69
69
  return nil if a_string.nil?
70
- cleanup(a_string).titleize.sub("Mc Donald's", "McDonald's")
70
+ titleize(cleanup(a_string))
71
71
  end
72
72
 
73
73
  # Remove extraneous whitespace from the string
@@ -83,7 +83,6 @@ module Eaternet
83
83
  (Time.now - File.mtime(path)).to_i / 86_400.0
84
84
  end
85
85
 
86
-
87
86
  private
88
87
 
89
88
  def self.expired?(cache_path)
@@ -101,5 +100,50 @@ module Eaternet
101
100
  `mkdir -p #{cache_dir}`
102
101
  cache_dir
103
102
  end
103
+
104
+ #
105
+ # A titleize that creates a usable title according to grammar rules.
106
+ #
107
+ ARTICLES = Set.new %w(a an and by di et for in is not of on or over the to under with)
108
+
109
+ def self.titleize(a_string)
110
+ # Only fix if all uppercase
111
+ return a_string unless all_uppercase?(a_string)
112
+
113
+ result = []
114
+
115
+ for word in a_string.downcase.split(/[[:space:]]/) # handle unicode
116
+ if irish?(word)
117
+ result << inflect_irish(word)
118
+ else
119
+ word = word.capitalize unless ARTICLES.include? word
120
+ result << word
121
+ end
122
+ end
123
+
124
+ just_capitalize(result.join(' '))
125
+ end
126
+
127
+ def self.all_uppercase?(a_string)
128
+ a_string.upcase == a_string
129
+ end
130
+
131
+ def self.irish?(a_string)
132
+ a_string =~ /^(ma?c)|(o').+$/ && !italian?(a_string)
133
+ end
134
+
135
+ def self.italian?(a_string)
136
+ %w(macaron macaroni macchiato machiavelli).include? a_string
137
+ end
138
+
139
+ def self.inflect_irish(a_string)
140
+ a_string =~ /^((ma?c)|(o'))(.+)$/
141
+ Regexp.last_match(1).capitalize + Regexp.last_match(4).capitalize
142
+ end
143
+
144
+ def self.just_capitalize(a_string)
145
+ head, tail = a_string.split(//, 2)
146
+ head.upcase + tail
147
+ end
104
148
  end
105
149
  end
@@ -1,3 +1,3 @@
1
1
  module Eaternet
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.4'
3
3
  end
@@ -18,7 +18,7 @@ class SnhdLivesTest < Minitest::Test
18
18
  VCR.use_cassette(SNHD_CASSETTE) do
19
19
  b = @@snhd.businesses.first
20
20
  assert_equal 'PR0000002', b.business_id
21
- assert_equal "McDonald's #3549 D Hotel", b.name
21
+ assert_equal "McDonald's #3549 D HOTEL", b.name
22
22
  assert_equal '301 Fremont St', b.address
23
23
  assert_equal 'Las Vegas', b.city
24
24
  assert_equal '89101-5600', b.postal_code
@@ -5,7 +5,6 @@ require 'timecop'
5
5
  require 'eaternet/util'
6
6
 
7
7
  class UtilTest < Minitest::Test
8
-
9
8
  def setup
10
9
  @file_contents = 'This is the file'
11
10
  @url = "http://downloadtest.com/file-#{rand(1_000_000)}.txt"
@@ -45,9 +44,67 @@ class UtilTest < Minitest::Test
45
44
  assert_requested :get, @url, times: 2
46
45
  end
47
46
 
48
- def test_properly_cleans_up_mcdonalds
49
- input = "McDonald's #3549 D HOTEL"
50
- desired_output = "McDonald's #3549 D Hotel"
51
- assert_equal desired_output, Eaternet::Util.cleanup_title(input)
47
+ #
48
+ # #cleanup_title
49
+ #
50
+
51
+ def assert_cleans_up_to(output, input)
52
+ assert_equal output, Eaternet::Util.cleanup_title(input)
53
+ end
54
+
55
+ def test_doesnt_mess_up_numeric_streets
56
+ assert_cleans_up_to '1654 86th St', '1654 86TH ST'
57
+ end
58
+
59
+ # Irish
60
+
61
+ def test_mcdonald_avenue
62
+ assert_cleans_up_to '1158 McDonald Avenue', '1158 MCDONALD AVENUE'
63
+ end
64
+
65
+ def test_mckennas_pub
66
+ assert_cleans_up_to "McKenna's Pub", "MCKENNA'S PUB"
67
+ end
68
+
69
+ def test_macdougal_street
70
+ assert_cleans_up_to '122 MacDougal St', '122 MACDOUGAL ST'
71
+ end
72
+
73
+ def test_o_sullivans_pub
74
+ assert_cleans_up_to "O'Sullivan's Pub", "O'SULLIVAN'S PUB"
75
+ end
76
+
77
+ # Italian
78
+
79
+ def test_macchiato
80
+ assert_cleans_up_to 'Macchiato Espresso Bar', 'MACCHIATO ESPRESSO BAR'
81
+ end
82
+
83
+ def test_di_vittorio
84
+ assert_cleans_up_to 'La Lanterna di Vittorio', 'LA LANTERNA DI VITTORIO'
85
+ end
86
+
87
+ def test_machiavelli
88
+ assert_cleans_up_to 'Machiavelli', 'MACHIAVELLI'
89
+ end
90
+
91
+ def test_macaroni
92
+ assert_cleans_up_to 'Macaroni', 'MACARONI'
93
+ end
94
+
95
+ # French
96
+
97
+ def test_rouge_et_blanc
98
+ assert_cleans_up_to 'Rouge et Blanc', 'ROUGE ET BLANC'
99
+ end
100
+
101
+ def test_macaron
102
+ assert_cleans_up_to 'Macaron', 'MACARON'
103
+ end
104
+
105
+ # Weird
106
+
107
+ def test_weird_stuff
108
+ assert_cleans_up_to 'aBcDeFg', 'aBcDeFg'
52
109
  end
53
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eaternet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter