Skip to content

Commit

Permalink
Bump DFC taxonomies to v1.0.2
Browse files Browse the repository at this point in the history
Finally replacing the last of the old DFC context URLs that are not
valid any more.
  • Loading branch information
mkllnk committed Nov 16, 2023
1 parent 5f3e176 commit ff2af57
Show file tree
Hide file tree
Showing 9 changed files with 2,584 additions and 2,471 deletions.
11 changes: 6 additions & 5 deletions engines/dfc_provider/app/services/quantitative_value_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def self.quantity(variant)
def self.unit(variant)
case variant.product.variant_unit
when "volume"
DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT.LITRE
DfcLoader.connector.MEASURES.LITRE
when "weight"
DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT.GRAM
DfcLoader.connector.MEASURES.GRAM
else
DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT.PIECE
DfcLoader.connector.MEASURES.PIECE
end
end

Expand Down Expand Up @@ -67,7 +67,7 @@ def self.apply(quantity, product)
#
# Until then, we can ignore Rubocop metrics, IMO.
def self.map_unit(unit) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
quantity_unit = DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT
quantity_unit = DfcLoader.connector.MEASURES

# The unit name is only set for items. The name is implied for weight and
# volume and filled in by `WeightsAndMeasures`.
Expand Down Expand Up @@ -110,7 +110,8 @@ def self.map_unit(unit) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/
else
# Labels may be provided one day:
# https://github.com/datafoodconsortium/connector-ruby/issues/18
label = unit.try(:semanticId)&.split("#")&.last || "items"
unit_id = unit.try(:semanticId)&.split("#")&.last&.split(":")&.last
label = unit_id || "items"
["items", label, 1]
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ class Connector
def import(json_string_or_io)
Importer.new.import(json_string_or_io)
end

# Monkey patch private method until fixed upstream:
# https://github.com/datafoodconsortium/connector-ruby/issues/19
def loadThesaurus(data)

Check warning on line 19 in engines/dfc_provider/lib/data_food_consortium/connector/connector.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Use snake_case for method names. Raw Output: engines/dfc_provider/lib/data_food_consortium/connector/connector.rb:19:11: C: Naming/MethodName: Use snake_case for method names.
taxonomy = data&.try(:[], 0) || data
return @parser.parse(taxonomy["@graph"])

Check warning on line 21 in engines/dfc_provider/lib/data_food_consortium/connector/connector.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Redundant `return` detected. Raw Output: engines/dfc_provider/lib/data_food_consortium/connector/connector.rb:21:9: C: Style/RedundantReturn: Redundant `return` detected.
end
end
end
end
7 changes: 4 additions & 3 deletions engines/dfc_provider/script/update-dfc-vocabularies
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

set -e

src="https://github.com/datafoodconsortium/taxonomies/releases/latest/download"
dst="`dirname $0`/../vendor"
mkdir -p "$dst"

curl 'http://static.datafoodconsortium.org/data/facets.json' > "$dst/facets.json"
curl 'http://static.datafoodconsortium.org/data/measures.json' > "$dst/measures.json"
curl 'http://static.datafoodconsortium.org/data/productTypes.json' > "$dst/productTypes.json"
curl --location "$src/facets.json" > "$dst/facets.json"
curl --location "$src/measures.json" > "$dst/measures.json"
curl --location "$src/productTypes.json" > "$dst/productTypes.json"
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
unless connector.MEASURES.respond_to?(:UNIT)
connector.loadMeasures(read_file("measures"))
end
connector.MEASURES.UNIT.QUANTITYUNIT.PIECE
connector.MEASURES.PIECE
end

it "imports a single object with simple properties" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
end

describe ".apply" do
let(:quantity_unit) { DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT }
let(:quantity_unit) { DfcLoader.connector.MEASURES }
let(:product) { Spree::Product.new }

it "uses items for anything unknown" do
Expand Down
Loading

0 comments on commit ff2af57

Please sign in to comment.