mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-24 01:57:46 -05:00
Move to crops helper
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module CropsHelper
|
||||
|
||||
def crop_or_parent(crop, attribute)
|
||||
default = crop.send(attribute)
|
||||
return default if default.present?
|
||||
|
||||
parent = crop
|
||||
while parent = parent.parent do
|
||||
while parent = parent.parent
|
||||
return parent.send(attribute) if parent&.send(attribute).present?
|
||||
end
|
||||
|
||||
@@ -38,4 +38,13 @@ module CropsHelper
|
||||
match = url.match(regex)
|
||||
match[1] if match
|
||||
end
|
||||
|
||||
def jsonld_data(crop)
|
||||
{
|
||||
'@context': "https://schema.org",
|
||||
'@type': "BioChemEntity",
|
||||
name: crop.name,
|
||||
taxonomicRange: crop.scientific_names.map(&:name)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user