beerdb 0.6.1 → 0.6.2
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.
- data/lib/beerdb/models/brewery.rb +129 -1
- data/lib/beerdb/version.rb +1 -1
- metadata +11 -11
| @@ -136,7 +136,48 @@ class Brewery < ActiveRecord::Base | |
| 136 136 |  | 
| 137 137 | 
             
                if value_brands.present?
         | 
| 138 138 | 
             
                  logger.debug " auto-adding brands >#{value_brands}<"
         | 
| 139 | 
            -
             | 
| 139 | 
            +
             | 
| 140 | 
            +
                  # remove optional english translation in square brackets ([]) e.g. Wien [Vienna]
         | 
| 141 | 
            +
                  value_brands = value_brands.gsub( /\[.+\]/, '' )
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                  # remove optional longer title part in () e.g. Las Palmas (de Gran Canaria), Palma (de Mallorca)
         | 
| 144 | 
            +
                  value_brands = value_brands.gsub( /\(.+\)/, '' )
         | 
| 145 | 
            +
                  
         | 
| 146 | 
            +
                  # remove optional longer title part in {} e.g. Ottakringer {Bio} or {Alkoholfrei}
         | 
| 147 | 
            +
                  value_brands = value_brands.gsub( /\{.+\}/, '' )
         | 
| 148 | 
            +
                  
         | 
| 149 | 
            +
                  value_brand_titles = value_brands.split( ',' )
         | 
| 150 | 
            +
                  
         | 
| 151 | 
            +
                  # pass 1) remove leading n trailing spaces
         | 
| 152 | 
            +
                  value_brand_titles = value_brand_titles.map { |value| value.strip }
         | 
| 153 | 
            +
                  
         | 
| 154 | 
            +
                  value_brand_titles.each do |brand_title|
         | 
| 155 | 
            +
                    
         | 
| 156 | 
            +
                    # autogenerate key from title
         | 
| 157 | 
            +
                    brand_key = title_to_key( brand_title )
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                    brand = Brand.find_by_key( brand_key )
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                    brand_attributes = {
         | 
| 162 | 
            +
                      title:      brand_title,
         | 
| 163 | 
            +
                      brewery_id: rec.id,
         | 
| 164 | 
            +
                      country_id: rec.country_id,
         | 
| 165 | 
            +
                      region_id:  rec.region_id,
         | 
| 166 | 
            +
                      city_id:    rec.city_id
         | 
| 167 | 
            +
                    }
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                    if brand.present?
         | 
| 170 | 
            +
                      logger.debug "update Brand #{brand.id}-#{brand.key}:"
         | 
| 171 | 
            +
                    else
         | 
| 172 | 
            +
                      logger.debug "create Brand:"
         | 
| 173 | 
            +
                      brand = Brand.new
         | 
| 174 | 
            +
                      brand_attributes[ :key ] = brand_key   # NB: new record; include/update key
         | 
| 175 | 
            +
                    end
         | 
| 176 | 
            +
                  
         | 
| 177 | 
            +
                    logger.debug brand_attributes.to_json
         | 
| 178 | 
            +
             | 
| 179 | 
            +
                    brand.update_attributes!( brand_attributes )
         | 
| 180 | 
            +
                  end
         | 
| 140 181 | 
             
                end
         | 
| 141 182 |  | 
| 142 183 | 
             
                ##################
         | 
| @@ -161,6 +202,93 @@ class Brewery < ActiveRecord::Base | |
| 161 202 |  | 
| 162 203 | 
             
              end # method create_or_update_from_values
         | 
| 163 204 |  | 
| 205 | 
            +
              ### todo/fix:
         | 
| 206 | 
            +
              # reuse method - put into helper in textutils or somewhere else ??
         | 
| 207 | 
            +
             | 
| 208 | 
            +
              def title_to_key( title )
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                  ## NB: downcase does NOT work for accented chars (thus, include in alternatives)
         | 
| 211 | 
            +
                  key = title.downcase
         | 
| 212 | 
            +
             | 
| 213 | 
            +
                  ## remove all whitespace and punctuation
         | 
| 214 | 
            +
                  key = key.gsub( /[ \t_\-\.()\[\]'"\/]/, '' )
         | 
| 215 | 
            +
             | 
| 216 | 
            +
                  ## remove special chars (e.g. %°&)
         | 
| 217 | 
            +
                  key = key.gsub( /[%&°]/, '' )
         | 
| 218 | 
            +
             | 
| 219 | 
            +
                  ##  turn accented char into ascii look alike if possible
         | 
| 220 | 
            +
                  ##
         | 
| 221 | 
            +
                  ## todo: add some more
         | 
| 222 | 
            +
                  ## see http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references  for more
         | 
| 223 | 
            +
                  
         | 
| 224 | 
            +
                  ## todo: add unicode codepoint name
         | 
| 225 | 
            +
                  
         | 
| 226 | 
            +
                  alternatives = [
         | 
| 227 | 
            +
                    ['ß', 'ss'],
         | 
| 228 | 
            +
                    ['æ', 'ae'],
         | 
| 229 | 
            +
                    ['ä', 'ae'],
         | 
| 230 | 
            +
                    ['ā', 'a' ],  # e.g. Liepājas
         | 
| 231 | 
            +
                    ['á', 'a' ],  # e.g. Bogotá, Králové
         | 
| 232 | 
            +
                    ['ã', 'a' ],  # e.g  São Paulo
         | 
| 233 | 
            +
                    ['ă', 'a' ],  # e.g. Chișinău
         | 
| 234 | 
            +
                    ['â', 'a' ],  # e.g  Goiânia
         | 
| 235 | 
            +
                    ['å', 'a' ],  # e.g. Vålerenga
         | 
| 236 | 
            +
                    ['ą', 'a' ],  # e.g. Śląsk
         | 
| 237 | 
            +
                    ['ç', 'c' ],  # e.g. São Gonçalo, Iguaçu, Neftçi
         | 
| 238 | 
            +
                    ['ć', 'c' ],  # e.g. Budućnost
         | 
| 239 | 
            +
                    ['č', 'c' ],  # e.g. Tradiční, Výčepní
         | 
| 240 | 
            +
                    ['é', 'e' ],  # e.g. Vélez, Králové
         | 
| 241 | 
            +
                    ['è', 'e' ],  # e.g. Rivières
         | 
| 242 | 
            +
                    ['ê', 'e' ],  # e.g. Grêmio
         | 
| 243 | 
            +
                    ['ě', 'e' ],  # e.g. Budějovice
         | 
| 244 | 
            +
                    ['ĕ', 'e' ],  # e.g. Svĕtlý
         | 
| 245 | 
            +
                    ['ė', 'e' ],  # e.g. Vėtra
         | 
| 246 | 
            +
                    ['ë', 'e' ],  # e.g. Skënderbeu
         | 
| 247 | 
            +
                    ['ğ', 'g' ],  # e.g. Qarabağ
         | 
| 248 | 
            +
                    ['ì', 'i' ],  # e.g. Potosì
         | 
| 249 | 
            +
                    ['í', 'i' ],  # e.g. Ústí
         | 
| 250 | 
            +
                    ['ł', 'l' ],  # e.g. Wisła, Wrocław
         | 
| 251 | 
            +
                    ['ñ', 'n' ],  # e.g. Porteño
         | 
| 252 | 
            +
                    ['ň', 'n' ],  # e.g. Plzeň, Třeboň
         | 
| 253 | 
            +
                    ['ö', 'oe'],
         | 
| 254 | 
            +
                    ['ő', 'o' ],  # e.g. Győri
         | 
| 255 | 
            +
                    ['ó', 'o' ],  # e.g. Colón, Łódź, Kraków
         | 
| 256 | 
            +
                    ['õ', 'o' ],  # e.g. Nõmme
         | 
| 257 | 
            +
                    ['ø', 'o' ],  # e.g. Fuglafjørdur, København
         | 
| 258 | 
            +
                    ['ř', 'r' ],  # e.g. Třeboň
         | 
| 259 | 
            +
                    ['ș', 's' ],  # e.g. Chișinău, București
         | 
| 260 | 
            +
                    ['ş', 's' ],  # e.g. Beşiktaş
         | 
| 261 | 
            +
                    ['š', 's' ],  # e.g. Košice
         | 
| 262 | 
            +
                    ['ť', 't' ],  # e.g. Měšťan
         | 
| 263 | 
            +
                    ['ü', 'ue'],
         | 
| 264 | 
            +
                    ['ú', 'u' ],  # e.g. Fútbol
         | 
| 265 | 
            +
                    ['ū', 'u' ],  # e.g. Sūduva
         | 
| 266 | 
            +
                    ['ů', 'u' ],  # e.g. Sládkův
         | 
| 267 | 
            +
                    ['ı', 'u' ],  # e.g. Bakı   # use u?? (Baku) why-why not?
         | 
| 268 | 
            +
                    ['ý', 'y' ],  # e.g. Nefitrovaný
         | 
| 269 | 
            +
                    ['ź', 'z' ],  # e.g. Łódź
         | 
| 270 | 
            +
                    ['ž', 'z' ],  # e.g. Domžale, Petržalka
         | 
| 271 | 
            +
             | 
| 272 | 
            +
                    ['Č', 'c' ],  # e.g. České
         | 
| 273 | 
            +
                    ['İ', 'i' ],  # e.g. İnter
         | 
| 274 | 
            +
                    ['Í', 'i' ],  # e.g. ÍBV
         | 
| 275 | 
            +
                    ['Ł', 'l' ],  # e.g. Łódź
         | 
| 276 | 
            +
                    ['Ö', 'oe' ], # e.g. Örebro
         | 
| 277 | 
            +
                    ['Ř', 'r' ],  # e.g. Řezák
         | 
| 278 | 
            +
                    ['Ś', 's' ],  # e.g. Śląsk
         | 
| 279 | 
            +
                    ['Š', 's' ],  # e.g. MŠK
         | 
| 280 | 
            +
                    ['Ş', 's' ],  # e.g. Şüvälan
         | 
| 281 | 
            +
                    ['Ú', 'u' ],  # e.g. Ústí, Újpest
         | 
| 282 | 
            +
                    ['Ž', 'z' ]   # e.g. Žilina
         | 
| 283 | 
            +
                  ]
         | 
| 284 | 
            +
                  
         | 
| 285 | 
            +
                  alternatives.each do |alt|
         | 
| 286 | 
            +
                    key = key.gsub( alt[0], alt[1] )
         | 
| 287 | 
            +
                  end
         | 
| 288 | 
            +
             | 
| 289 | 
            +
                  key
         | 
| 290 | 
            +
              end # method title_to_key
         | 
| 291 | 
            +
             | 
| 164 292 | 
             
            end # class Brewery
         | 
| 165 293 |  | 
| 166 294 |  | 
    
        data/lib/beerdb/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: beerdb
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.6. | 
| 4 | 
            +
              version: 0.6.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -13,7 +13,7 @@ date: 2013-05-05 00:00:00.000000000 Z | |
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: activerecord
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &84738480 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ~>
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: '3.2'
         | 
| 22 22 | 
             
              type: :runtime
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *84738480
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: worlddb
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &84738260 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ~>
         | 
| @@ -32,10 +32,10 @@ dependencies: | |
| 32 32 | 
             
                    version: '1.6'
         | 
| 33 33 | 
             
              type: :runtime
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *84738260
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 37 | 
             
              name: commander
         | 
| 38 | 
            -
              requirement: & | 
| 38 | 
            +
              requirement: &84738040 !ruby/object:Gem::Requirement
         | 
| 39 39 | 
             
                none: false
         | 
| 40 40 | 
             
                requirements:
         | 
| 41 41 | 
             
                - - ~>
         | 
| @@ -43,10 +43,10 @@ dependencies: | |
| 43 43 | 
             
                    version: 4.1.3
         | 
| 44 44 | 
             
              type: :runtime
         | 
| 45 45 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements: * | 
| 46 | 
            +
              version_requirements: *84738040
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: rdoc
         | 
| 49 | 
            -
              requirement: & | 
| 49 | 
            +
              requirement: &84737820 !ruby/object:Gem::Requirement
         | 
| 50 50 | 
             
                none: false
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ~>
         | 
| @@ -54,10 +54,10 @@ dependencies: | |
| 54 54 | 
             
                    version: '3.10'
         | 
| 55 55 | 
             
              type: :development
         | 
| 56 56 | 
             
              prerelease: false
         | 
| 57 | 
            -
              version_requirements: * | 
| 57 | 
            +
              version_requirements: *84737820
         | 
| 58 58 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 59 59 | 
             
              name: hoe
         | 
| 60 | 
            -
              requirement: & | 
| 60 | 
            +
              requirement: &84737600 !ruby/object:Gem::Requirement
         | 
| 61 61 | 
             
                none: false
         | 
| 62 62 | 
             
                requirements:
         | 
| 63 63 | 
             
                - - ~>
         | 
| @@ -65,7 +65,7 @@ dependencies: | |
| 65 65 | 
             
                    version: '3.3'
         | 
| 66 66 | 
             
              type: :development
         | 
| 67 67 | 
             
              prerelease: false
         | 
| 68 | 
            -
              version_requirements: * | 
| 68 | 
            +
              version_requirements: *84737600
         | 
| 69 69 | 
             
            description: beerdb - beer.db command line tool
         | 
| 70 70 | 
             
            email: beerdb@googlegroups.com
         | 
| 71 71 | 
             
            executables:
         |