openbeautyfacts 0.6.0 → 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.
- checksums.yaml +4 -4
- data/README.md +21 -6
- data/Rakefile +5 -3
- data/lib/openbeautyfacts/additive.rb +9 -39
- data/lib/openbeautyfacts/allergen.rb +14 -22
- data/lib/openbeautyfacts/brand.rb +14 -22
- data/lib/openbeautyfacts/category.rb +14 -22
- data/lib/openbeautyfacts/city.rb +14 -22
- data/lib/openbeautyfacts/contributor.rb +14 -22
- data/lib/openbeautyfacts/country.rb +14 -22
- data/lib/openbeautyfacts/entry_date.rb +15 -23
- data/lib/openbeautyfacts/faq.rb +16 -41
- data/lib/openbeautyfacts/ingredient.rb +14 -22
- data/lib/openbeautyfacts/ingredient_that_may_be_from_palm_oil.rb +14 -22
- data/lib/openbeautyfacts/label.rb +14 -22
- data/lib/openbeautyfacts/last_edit_date.rb +15 -23
- data/lib/openbeautyfacts/locale.rb +8 -31
- data/lib/openbeautyfacts/manufacturing_place.rb +14 -22
- data/lib/openbeautyfacts/mission.rb +16 -63
- data/lib/openbeautyfacts/number_of_ingredients.rb +15 -23
- data/lib/openbeautyfacts/origin.rb +14 -22
- data/lib/openbeautyfacts/packager_code.rb +14 -22
- data/lib/openbeautyfacts/packaging.rb +14 -22
- data/lib/openbeautyfacts/period_after_opening.rb +14 -22
- data/lib/openbeautyfacts/press.rb +16 -47
- data/lib/openbeautyfacts/product.rb +18 -164
- data/lib/openbeautyfacts/product_state.rb +14 -22
- data/lib/openbeautyfacts/purchase_place.rb +14 -22
- data/lib/openbeautyfacts/store.rb +14 -22
- data/lib/openbeautyfacts/trace.rb +14 -22
- data/lib/openbeautyfacts/user.rb +15 -30
- data/lib/openbeautyfacts/version.rb +3 -1
- data/lib/openbeautyfacts.rb +6 -9
- data/test/fixtures/additives.yml +48 -0
- data/test/fixtures/brands.yml +48 -0
- data/test/fixtures/entry_dates.yml +48 -0
- data/test/fixtures/entry_dates_locale.yml +48 -0
- data/test/fixtures/faq.yml +48 -0
- data/test/fixtures/fetch_product_3600550362626.yml +54 -0
- data/test/fixtures/index.yml +48 -0
- data/test/fixtures/ingredients.yml +99 -0
- data/test/fixtures/ingredients_locale.yml +99 -0
- data/test/fixtures/last_edit_dates.yml +48 -0
- data/test/fixtures/last_edit_dates_locale.yml +48 -0
- data/test/fixtures/login_user.yml +363 -0
- data/test/fixtures/mission.yml +48 -0
- data/test/fixtures/missions.yml +48 -0
- data/test/fixtures/number_of_ingredients_locale.yml +48 -0
- data/test/fixtures/numbers_of_ingredients.yml +48 -0
- data/test/fixtures/press.yml +48 -0
- data/test/fixtures/product_3600550362626.yml +54 -0
- data/test/fixtures/product_states.yml +48 -0
- data/test/fixtures/product_states_locale.yml +48 -0
- data/test/fixtures/products_for_brand.yml +99 -0
- data/test/fixtures/products_for_entry_date.yml +99 -0
- data/test/fixtures/products_for_ingredient.yml +99 -0
- data/test/fixtures/products_for_last_edit_date.yml +99 -0
- data/test/fixtures/products_for_number_of_ingredients.yml +99 -0
- data/test/fixtures/products_for_period_after_opening.yml +99 -0
- data/test/fixtures/products_for_state.yml +99 -0
- data/test/fixtures/products_with_additive.yml +99 -0
- data/test/fixtures/search_doux.yml +105 -0
- data/test/fixtures/search_doux_1_000_000.yml +54 -0
- data/test/minitest_helper.rb +5 -3
- data/test/test_openbeautyfacts.rb +129 -97
- metadata +63 -21
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Label <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'labels',
|
|
9
|
-
'uk' => 'labels',
|
|
10
|
-
'us' => 'labels',
|
|
11
|
-
'world' => 'labels'
|
|
12
|
-
}
|
|
4
|
+
class Label < Openfoodfacts::Label
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
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
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class LastEditDate <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'dates-de-derniere-modification',
|
|
9
|
-
'uk' => 'last-edit-dates',
|
|
10
|
-
'us' => 'last-edit-dates',
|
|
11
|
-
'world' => 'last-edit-dates'
|
|
12
|
-
}
|
|
4
|
+
class LastEditDate < Openfoodfacts::LastEditDate
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
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,44 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Locale <
|
|
5
|
-
|
|
4
|
+
class Locale < Openfoodfacts::Locale
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
6
|
GLOBAL = 'world'
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
7
8
|
|
|
8
9
|
class << self
|
|
9
|
-
|
|
10
|
-
# Get locales
|
|
11
|
-
#
|
|
10
|
+
# Override all method to use openbeautyfacts domain
|
|
12
11
|
def all(domain: DEFAULT_DOMAIN)
|
|
13
|
-
|
|
14
|
-
url = "https://#{GLOBAL}.#{domain}/#{path}"
|
|
15
|
-
json = URI.open(url).read
|
|
16
|
-
hash = JSON.parse(json)
|
|
17
|
-
|
|
18
|
-
hash.map { |pair|
|
|
19
|
-
locale_from_pair(pair, domain: domain)
|
|
20
|
-
}.compact
|
|
12
|
+
super(domain: domain)
|
|
21
13
|
end
|
|
22
14
|
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
def locale_from_link(link)
|
|
26
|
-
locale = link[/^https?:\/\/([^.]+)\./i, 1]
|
|
27
|
-
locale unless locale.nil? || locale == 'static'
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Return locale from pair
|
|
31
|
-
#
|
|
15
|
+
# Override locale_from_pair method to use openbeautyfacts domain
|
|
32
16
|
def locale_from_pair(pair, domain: DEFAULT_DOMAIN)
|
|
33
|
-
|
|
34
|
-
{
|
|
35
|
-
"name" => pair.last.strip,
|
|
36
|
-
"code" => code,
|
|
37
|
-
"url" => "https://#{code}.#{domain}"
|
|
38
|
-
} if code
|
|
17
|
+
super(pair, domain: domain)
|
|
39
18
|
end
|
|
40
|
-
|
|
41
19
|
end
|
|
42
|
-
|
|
43
20
|
end
|
|
44
21
|
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class ManufacturingPlace <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'lieux-de-fabrication',
|
|
9
|
-
'uk' => 'manufacturing-places',
|
|
10
|
-
'us' => 'manufacturing-places',
|
|
11
|
-
'world' => 'manufacturing-places'
|
|
12
|
-
}
|
|
4
|
+
class ManufacturingPlace < Openfoodfacts::ManufacturingPlace
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
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,72 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
require 'open-uri'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
4
3
|
module Openbeautyfacts
|
|
5
|
-
class Mission <
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
'fr' => 'missions',
|
|
10
|
-
'uk' => 'missions',
|
|
11
|
-
'us' => 'missions',
|
|
12
|
-
'world' => 'missions'
|
|
13
|
-
}
|
|
4
|
+
class Mission < Openfoodfacts::Mission
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
14
8
|
|
|
15
9
|
class << self
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
dom.css('#missions li').map do |mission_dom|
|
|
23
|
-
links = mission_dom.css('a')
|
|
24
|
-
|
|
25
|
-
attributes = {
|
|
26
|
-
"title" => links.first.text.strip,
|
|
27
|
-
"url" => URI.join(url, links.first.attr('href')).to_s,
|
|
28
|
-
"description" => mission_dom.css('div').first.children[2].text.gsub('→', '').strip,
|
|
29
|
-
"users_count" => links.last.text[/(\d+)/, 1].to_i
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
new(attributes)
|
|
33
|
-
end
|
|
34
|
-
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
|
|
35
15
|
end
|
|
36
16
|
end
|
|
37
17
|
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
dom = Nokogiri::HTML.fragment(html)
|
|
44
|
-
|
|
45
|
-
description = dom.css('#description').first
|
|
46
|
-
|
|
47
|
-
# Remove "All missions" link
|
|
48
|
-
users = dom.css('#main_column a')[0..-2].map do |user_link|
|
|
49
|
-
User.new(
|
|
50
|
-
"user_id" => user_link.text.strip,
|
|
51
|
-
"url" => URI.join(self.url, user_link.attr('href')).to_s,
|
|
52
|
-
)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
mission = {
|
|
56
|
-
"title" => dom.css('h1').first.text.strip,
|
|
57
|
-
"description" => description.text.strip,
|
|
58
|
-
"description_long" => description.next.text.strip,
|
|
59
|
-
|
|
60
|
-
"users" => users,
|
|
61
|
-
"users_count" => users.count
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
self.merge!(mission)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
self
|
|
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
|
|
68
23
|
end
|
|
69
|
-
alias_method :reload, :fetch
|
|
70
|
-
|
|
71
24
|
end
|
|
72
|
-
end
|
|
25
|
+
end
|
|
@@ -1,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class NumberOfIngredients <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'nombres-d-ingredients',
|
|
9
|
-
'uk' => 'numbers-of-ingredients',
|
|
10
|
-
'us' => 'numbers-of-ingredients',
|
|
11
|
-
'world' => 'numbers-of-ingredients'
|
|
12
|
-
}
|
|
4
|
+
class NumberOfIngredients < Openfoodfacts::NumberOfIngredients
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
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,33 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Origin <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'origines',
|
|
9
|
-
'uk' => 'origins',
|
|
10
|
-
'us' => 'origins',
|
|
11
|
-
'world' => 'origins'
|
|
12
|
-
}
|
|
4
|
+
class Origin < Openfoodfacts::Origin
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
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
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class PackagerCode <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'codes-emballeurs',
|
|
9
|
-
'uk' => 'packager-codes',
|
|
10
|
-
'us' => 'packager-codes',
|
|
11
|
-
'world' => 'packager-codes'
|
|
12
|
-
}
|
|
4
|
+
class PackagerCode < Openfoodfacts::PackagerCode
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
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
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class Packaging <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'conditionnements',
|
|
9
|
-
'uk' => 'packaging',
|
|
10
|
-
'us' => 'packaging',
|
|
11
|
-
'world' => 'packaging'
|
|
12
|
-
}
|
|
4
|
+
class Packaging < Openfoodfacts::Packaging
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
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
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Openbeautyfacts
|
|
4
|
-
class PeriodAfterOpening <
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'fr' => 'durees-d-utilisation-apres-ouverture',
|
|
9
|
-
'uk' => 'periods-after-opening',
|
|
10
|
-
'us' => 'periods-after-opening',
|
|
11
|
-
'world' => 'periods-after-opening'
|
|
12
|
-
}
|
|
4
|
+
class PeriodAfterOpening < Openfoodfacts::PeriodAfterOpening
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
13
8
|
|
|
14
9
|
class << self
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
#
|
|
27
|
-
#
|
|
18
|
+
# Override products method to use openbeautyfacts domain if it exists
|
|
28
19
|
def products(page: -1)
|
|
29
|
-
|
|
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,56 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
require 'nokogiri'
|
|
3
|
-
require 'open-uri'
|
|
4
|
-
require 'time'
|
|
1
|
+
# frozen_string_literal: true
|
|
5
2
|
|
|
6
3
|
module Openbeautyfacts
|
|
7
|
-
class Press <
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
'fr' => 'presse',
|
|
12
|
-
'uk' => 'press',
|
|
13
|
-
'us' => 'press',
|
|
14
|
-
'world' => 'press'
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
LOCALE_DATE_FORMATS = {
|
|
18
|
-
'fr' => '%d/%m/%Y',
|
|
19
|
-
'uk' => '%m/%d/%Y',
|
|
20
|
-
'us' => '%m/%d/%Y',
|
|
21
|
-
'world' => '%m/%d/%Y'
|
|
22
|
-
}
|
|
4
|
+
class Press < Openfoodfacts::Press
|
|
5
|
+
# Override constants for openbeautyfacts domain
|
|
6
|
+
DEFAULT_LOCALE = Locale::GLOBAL
|
|
7
|
+
DEFAULT_DOMAIN = 'openbeautyfacts.org'
|
|
23
8
|
|
|
24
9
|
class << self
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
titles = dom.css('#main_column li')
|
|
31
|
-
titles.each_with_index.map do |item, index|
|
|
32
|
-
data = item.inner_html.split(' - ')
|
|
33
|
-
|
|
34
|
-
link = Nokogiri::HTML.fragment(data.first).css('a')
|
|
35
|
-
attributes = {
|
|
36
|
-
"title" => link.text.strip,
|
|
37
|
-
"url" => link.attr('href').value
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
last = Nokogiri::HTML.fragment(data.last)
|
|
41
|
-
if date_format = LOCALE_DATE_FORMATS[locale] and date = last.text.strip[/\d+\/\d+\/\d+\z/, 0]
|
|
42
|
-
attributes["date"] = DateTime.strptime(date, date_format)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
if data.length >= 3
|
|
46
|
-
attributes["source"] = Nokogiri::HTML.fragment(data[-2]).text.strip
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
new(attributes)
|
|
50
|
-
end
|
|
51
|
-
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
|
|
52
15
|
end
|
|
53
16
|
end
|
|
54
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
|
|
55
24
|
end
|
|
56
25
|
end
|