openbeautyfacts 0.6.3 → 0.10.0

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +19 -1
  3. data/Rakefile +5 -3
  4. data/lib/openbeautyfacts/additive.rb +9 -39
  5. data/lib/openbeautyfacts/allergen.rb +14 -22
  6. data/lib/openbeautyfacts/brand.rb +14 -22
  7. data/lib/openbeautyfacts/category.rb +14 -22
  8. data/lib/openbeautyfacts/city.rb +14 -22
  9. data/lib/openbeautyfacts/contributor.rb +14 -22
  10. data/lib/openbeautyfacts/country.rb +14 -22
  11. data/lib/openbeautyfacts/entry_date.rb +15 -23
  12. data/lib/openbeautyfacts/faq.rb +16 -41
  13. data/lib/openbeautyfacts/ingredient.rb +14 -22
  14. data/lib/openbeautyfacts/ingredient_that_may_be_from_palm_oil.rb +14 -22
  15. data/lib/openbeautyfacts/label.rb +14 -22
  16. data/lib/openbeautyfacts/last_edit_date.rb +15 -23
  17. data/lib/openbeautyfacts/locale.rb +8 -31
  18. data/lib/openbeautyfacts/manufacturing_place.rb +14 -22
  19. data/lib/openbeautyfacts/mission.rb +16 -63
  20. data/lib/openbeautyfacts/number_of_ingredients.rb +15 -23
  21. data/lib/openbeautyfacts/origin.rb +14 -22
  22. data/lib/openbeautyfacts/packager_code.rb +14 -22
  23. data/lib/openbeautyfacts/packaging.rb +14 -22
  24. data/lib/openbeautyfacts/period_after_opening.rb +14 -22
  25. data/lib/openbeautyfacts/press.rb +16 -47
  26. data/lib/openbeautyfacts/product.rb +18 -175
  27. data/lib/openbeautyfacts/product_state.rb +14 -22
  28. data/lib/openbeautyfacts/purchase_place.rb +14 -22
  29. data/lib/openbeautyfacts/store.rb +14 -22
  30. data/lib/openbeautyfacts/trace.rb +14 -22
  31. data/lib/openbeautyfacts/user.rb +15 -30
  32. data/lib/openbeautyfacts/version.rb +3 -1
  33. data/lib/openbeautyfacts.rb +6 -9
  34. data/test/fixtures/additives.yml +48 -0
  35. data/test/fixtures/brands.yml +48 -0
  36. data/test/fixtures/entry_dates.yml +48 -0
  37. data/test/fixtures/entry_dates_locale.yml +48 -0
  38. data/test/fixtures/faq.yml +48 -0
  39. data/test/fixtures/fetch_product_3600550362626.yml +54 -0
  40. data/test/fixtures/index.yml +48 -0
  41. data/test/fixtures/ingredients.yml +99 -0
  42. data/test/fixtures/ingredients_locale.yml +99 -0
  43. data/test/fixtures/last_edit_dates.yml +48 -0
  44. data/test/fixtures/last_edit_dates_locale.yml +48 -0
  45. data/test/fixtures/login_user.yml +363 -0
  46. data/test/fixtures/mission.yml +48 -0
  47. data/test/fixtures/missions.yml +48 -0
  48. data/test/fixtures/number_of_ingredients_locale.yml +48 -0
  49. data/test/fixtures/numbers_of_ingredients.yml +48 -0
  50. data/test/fixtures/press.yml +48 -0
  51. data/test/fixtures/product_3600550362626.yml +54 -0
  52. data/test/fixtures/product_states.yml +48 -0
  53. data/test/fixtures/product_states_locale.yml +48 -0
  54. data/test/fixtures/products_for_brand.yml +99 -0
  55. data/test/fixtures/products_for_entry_date.yml +99 -0
  56. data/test/fixtures/products_for_ingredient.yml +99 -0
  57. data/test/fixtures/products_for_last_edit_date.yml +99 -0
  58. data/test/fixtures/products_for_number_of_ingredients.yml +99 -0
  59. data/test/fixtures/products_for_period_after_opening.yml +99 -0
  60. data/test/fixtures/products_for_state.yml +99 -0
  61. data/test/fixtures/products_with_additive.yml +99 -0
  62. data/test/fixtures/search_doux.yml +105 -0
  63. data/test/fixtures/search_doux_1_000_000.yml +54 -0
  64. data/test/minitest_helper.rb +5 -3
  65. data/test/test_openbeautyfacts.rb +129 -97
  66. metadata +59 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 101290dad91405b7afc40eace7e6621731eaf08add56549ad55af3912c55b3c2
4
- data.tar.gz: a0708f6c073740c8534e9ba872f7f742c4ffe4b5a5be63a9ee4e828345fadfa2
3
+ metadata.gz: ee3e3eb895b24332b15083b9e7ab0d0fe14d711792b2bf3e83c4de35e0ccada7
4
+ data.tar.gz: 976b0855a3e6653b90412d53cb132a69cd34e2d56e099da89b30b9724f19e75f
5
5
  SHA512:
6
- metadata.gz: e4b272685be3c8099c623e76c057ee00c67f86a1bda69fd24088a41263b3b37e117f1d6341a9d71bde99d640dc4c1da55fbd7277cb5b9fa84613ad706da2cb9e
7
- data.tar.gz: 604f209cca866626667ae75bc1f873f11a73fe87adfd177e70ee449c627919aa42d57c4fb1f0a6b55451f7abef758908d4001f18b8cdbc2461a30764608326a1
6
+ metadata.gz: 0dfbf80e11a3721d1f34e5a742bd258f3064a52cd258f663c66646320448e9366bd9c2743ead584d942e9b7c2798c13f24de90442b84b4d478f34f7083573be8
7
+ data.tar.gz: 5f57a30b0d77f9e9dd219cc17383f330b7f0db32a3265414e0ad169cd62705fb617f78cb845913a9fbdfdd447131ae7dd50953eb15bb47c193e020a89ad26476
data/README.md CHANGED
@@ -1,4 +1,10 @@
1
- # Open Beauty Facts
1
+ # Open Beauty Facts Ruby SDK
2
+
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://static.openbeautyfacts.org/images/logos/obf-logo-horizontal-dark.png?refresh_github_cache=1">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://static.openbeautyfacts.org/images/logos/obf-logo-horizontal-light.png?refresh_github_cache=1">
6
+ <img height="48" src="https://static.openbeautyfacts.org/images/logos/obf-logo-horizontal-light.svg"/>
7
+ </picture>
2
8
 
3
9
  [![Gem Version](https://badge.fury.io/rb/openbeautyfacts.svg)](https://badge.fury.io/rb/openbeautyfacts)
4
10
  [![Build Status](https://github.com/openfoodfacts/openbeautyfacts-ruby/actions/workflows/ruby.yml/badge.svg)](https://github.com/openfoodfacts/openbeautyfacts-ruby/actions/workflows/ruby.yml)
@@ -6,6 +12,9 @@
6
12
  [![Documentation](https://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby.svg?branch=master)](https://inch-ci.org/github/openfoodfacts/openbeautyfacts-ruby)
7
13
 
8
14
  API Wrapper for [Open Beauty Facts](https://openbeautyfacts.org/), the open database about beauty products.
15
+ - We have a similar package for food: https://github.com/openfoodfacts/openfoodfacts-ruby
16
+ - Note: This package needs updates for the newest APIs.
17
+ - Please see on https://wiki.openfoodfacts.org/API/Ruby how to join the community to help
9
18
 
10
19
  ## Installation
11
20
 
@@ -112,3 +121,12 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
112
121
  3. Commit your changes (`git commit -am 'Add some feature'`)
113
122
  4. Push to the branch (`git push origin my-new-feature`)
114
123
  5. Create a new Pull Request
124
+
125
+ ## Using this SDK and Third party applications
126
+
127
+ - If you use this SDK, feel free to open a PR to add your application in the list in [REUSERS.md](https://github.com/openfoodfacts/openbeautyfacts-ruby/blob/develop/REUSERS.md)
128
+ - Make sure you comply with the OdBL licence, mentioning the Source of your data, and ensuring to avoid combining non free data you can't release legally as open data. Another requirement is contributing back any product you add using this SDK.
129
+ - Please get in touch at reuse@openfoodfacts.org
130
+ - We are very interested in learning what the Open Food Facts data is used for. It is not mandatory, but we would very much appreciate it if you tell us about your re-uses (https://forms.gle/hwaeqBfs8ywwhbTg8) so that we can share them with the Open Food Facts community. You can also fill this form to get a chance to get your app featured: https://forms.gle/hwaeqBfs8ywwhbTg8
131
+
132
+ ## Authors
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
 
4
6
  Rake::TestTask.new do |task|
5
- task.libs << "lib"
6
- task.libs << "test"
7
- task.pattern = "test/test_*.rb"
7
+ task.libs << 'lib'
8
+ task.libs << 'test'
9
+ task.pattern = 'test/test_*.rb'
8
10
  end
9
11
 
10
12
  task default: :test
@@ -1,51 +1,21 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class Additive < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'additifs',
9
- 'uk' => 'additives',
10
- 'us' => 'additives',
11
- 'world' => 'additives'
12
- }
4
+ class Additive < Openfoodfacts::Additive
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get additives
17
- #
10
+ # Override all method to use openbeautyfacts domain
18
11
  def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- page_url = "https://#{locale}.#{domain}/#{path}"
21
-
22
- Product.tags_from_page(self, page_url) do |tag|
23
- columns = tag.css('td')
24
-
25
- link = tag.css('a').first
26
- attributes = {
27
- "name" => link.text.strip,
28
- "url" => URI.join(page_url, link.attr('href')).to_s,
29
- "products_count" => columns[1].text.to_i,
30
- }
31
-
32
- riskiness = columns[3].attr('class')
33
- if riskiness
34
- attributes["riskiness"] = riskiness[/level_(\d+)/, 1].to_i
35
- end
36
-
37
- new(attributes)
38
- end
39
- end
12
+ super(locale: locale, domain: domain)
40
13
  end
41
-
42
14
  end
43
15
 
44
- # Get products with additive
45
- #
16
+ # Override products method to use openbeautyfacts domain
46
17
  def products(page: -1)
47
- Product.from_website_page(url, page: page, products_count: products_count) if url
18
+ super(page: page)
48
19
  end
49
-
50
20
  end
51
21
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class Allergen < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'allergenes',
9
- 'uk' => 'allergens',
10
- 'us' => 'allergens',
11
- 'world' => 'allergens'
12
- }
4
+ class Allergen < Openfoodfacts::Allergen
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get allergens
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products with allergen
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
25
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class Brand < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'marques',
9
- 'uk' => 'brands',
10
- 'us' => 'brands',
11
- 'world' => 'brands'
12
- }
4
+ class Brand < Openfoodfacts::Brand
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get product brands
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products with brand
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
25
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class Category < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'categories',
9
- 'uk' => 'categories',
10
- 'us' => 'categories',
11
- 'world' => 'categories'
12
- }
4
+ class Category < Openfoodfacts::Category
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get categories
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products with category
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
25
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class City < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'communes',
9
- 'uk' => 'cities',
10
- 'us' => 'cities',
11
- 'world' => 'cities'
12
- }
4
+ class City < Openfoodfacts::City
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get cities
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products with city
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
25
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class Contributor < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'contributeurs',
9
- 'uk' => 'contributors',
10
- 'us' => 'contributors',
11
- 'world' => 'contributors'
12
- }
4
+ class Contributor < Openfoodfacts::Contributor
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get contributors
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products for contributor
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
25
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class Country < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'pays',
9
- 'uk' => 'countries',
10
- 'us' => 'countries',
11
- 'world' => 'countries'
12
- }
4
+ class Country < Openfoodfacts::Country
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get countries
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products with country
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
25
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class EntryDate < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'dates-d-ajout',
9
- 'uk' => 'entry-dates',
10
- 'us' => 'entry-dates',
11
- 'world' => 'entry-dates'
12
- }
4
+ class EntryDate < Openfoodfacts::EntryDate
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get entry dates
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products with entry date
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
- end
25
+ end
@@ -1,50 +1,25 @@
1
- require 'hashie'
2
- require 'nokogiri'
3
- require 'open-uri'
1
+ # frozen_string_literal: true
4
2
 
5
3
  module Openbeautyfacts
6
- class Faq < Hashie::Mash
7
-
8
- # TODO: Add more locales
9
- LOCALE_PATHS = {
10
- 'fr' => 'questions-frequentes',
11
- 'uk' => 'faq',
12
- 'us' => 'faq',
13
- 'world' => 'faq'
14
- }
4
+ class Faq < Openfoodfacts::Faq
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
15
8
 
16
9
  class << self
17
- def items(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
18
- if path = LOCALE_PATHS[locale]
19
- html = URI.open("https://#{locale}.#{domain}/#{path}").read
20
- dom = Nokogiri::HTML.fragment(html)
21
-
22
- titles = dom.css('#main_column h2')
23
- titles.each_with_index.map do |item, index|
24
- paragraphs = []
25
-
26
- element = item.next_sibling
27
- while !element.nil? && element.node_name != 'h2'
28
- if element.node_name == 'p'
29
- paragraphs.push(element)
30
- end
31
-
32
- element = element.next_sibling
33
- end
34
-
35
- if index == titles.length - 1
36
- paragraphs = paragraphs[0..-3]
37
- end
38
-
39
- new({
40
- "question" => item.text.strip,
41
- "answer" => paragraphs.map { |paragraph| paragraph.text.strip.gsub(/\r?\n/, ' ') }.join("\n\n"),
42
- "answer_html" => paragraphs.map(&:to_html).join
43
- })
44
- end
45
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
46
15
  end
47
16
  end
48
17
 
18
+ # Override products method to use openbeautyfacts domain if it exists
19
+ def products(page: -1)
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
23
+ end
49
24
  end
50
25
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class Ingredient < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'ingredients',
9
- 'uk' => 'ingredients',
10
- 'us' => 'ingredients',
11
- 'world' => 'ingredients'
12
- }
4
+ class Ingredient < Openfoodfacts::Ingredient
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get labels
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products with label
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
25
  end
@@ -1,33 +1,25 @@
1
- require 'hashie'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Openbeautyfacts
4
- class IngredientThatMayBeFromPalmOil < Hashie::Mash
5
-
6
- # TODO: Add more locales
7
- LOCALE_PATHS = {
8
- 'fr' => 'ingredients-pouvant-etre-issus-de-l-huile-de-palme',
9
- 'uk' => 'ingredients-that-may-be-from-palm-oil',
10
- 'us' => 'ingredients-that-may-be-from-palm-oil',
11
- 'world' => 'ingredients-that-may-be-from-palm-oil'
12
- }
4
+ class IngredientThatMayBeFromPalmOil < Openfoodfacts::IngredientThatMayBeFromPalmOil
5
+ # Override constants for openbeautyfacts domain
6
+ DEFAULT_LOCALE = Locale::GLOBAL
7
+ DEFAULT_DOMAIN = 'openbeautyfacts.org'
13
8
 
14
9
  class << self
15
-
16
- # Get ingredients that may be from palm oil
17
- #
18
- def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
19
- if path = LOCALE_PATHS[locale]
20
- Product.tags_from_page(self, "https://#{locale}.#{domain}/#{path}")
21
- end
10
+ # Override all method to use openbeautyfacts domain if it exists
11
+ def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN, **options)
12
+ super(locale: locale, domain: domain, **options)
13
+ rescue NoMethodError
14
+ # Method doesn't exist in parent class, skip
22
15
  end
23
-
24
16
  end
25
17
 
26
- # Get products with ingredient that may be from palm oil
27
- #
18
+ # Override products method to use openbeautyfacts domain if it exists
28
19
  def products(page: -1)
29
- Product.from_website_page(url, page: page, products_count: products_count) if url
20
+ super(page: page)
21
+ rescue NoMethodError
22
+ # Method doesn't exist in parent class, skip
30
23
  end
31
-
32
24
  end
33
25
  end