Skip to content

Commit

Permalink
Code review edits
Browse files Browse the repository at this point in the history
  • Loading branch information
anselmbradford committed May 31, 2014
1 parent cf03e1b commit 814b765
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 50 deletions.
25 changes: 5 additions & 20 deletions app/helpers/application_helper.rb
Expand Up @@ -61,22 +61,7 @@ def emergency_terms
# @return [Hash] Defines which query terms will display an info box
# on the results page for select keywords.
def info_box_terms
{
'wic' =>
['women, infants, and children','WIC/Women, Infants, & Children'],
'sfmnp' =>
["senior farmers' market nutrition program",
"SFMNP/Food vouchers for seniors"],
'market match' => [],
'calfresh' => ['food stamps','snap','calfresh/food stamps'],
'health care reform' => ['affordable care act','health insurance']
}
end

# @return [Hash] Defines which query terms will display an info box
# on the results page for select keywords.
def info_box_terms
YAML.load(File.read(File.expand_path("#{Rails.root}/config/terminology.yml", __FILE__)))
YAML.load(File.read(File.expand_path("#{Rails.root}/config/#{ Rails.env.test? ? 'test/' : '' }terminology.yml", __FILE__)))
end

# @return [Hash] Returns a hash that should be fed into a `render` command
Expand All @@ -86,19 +71,19 @@ def dynamic_partial
if params[:keyword].present?
keyword = params[:keyword].downcase
# Create 2 arrays: one containing the search terms of the info_box_terms,
# and the other containing all the synonymns of those terms.
# and the other containing all the synonyms of those terms.
main_terms = info_box_terms.keys
synonyms = []
info_box_terms.select { |k,v| synonyms.push(v['synonymns']) }
info_box_terms.select { |k,v| synonyms.push(v['synonyms']) }
synonyms.flatten!

# Check if the keyword matches any of the terms or synonymns.
# Check if the keyword matches any of the terms or synonyms.
if (main_terms + synonyms).include?(keyword)

# If the keyword matches a value, we find the corresponding key.
# The key is what the partial name corresponds to.
if synonyms.include?(keyword)
partial = info_box_terms.find { |k,v| v['synonymns'].include? keyword }.first
partial = info_box_terms.find { |k,v| v['synonyms'].include? keyword }.first
# Otherwise, it means the keyword matches a key
else
partial = keyword
Expand Down
60 changes: 30 additions & 30 deletions config/terminology.yml
Expand Up @@ -6,10 +6,10 @@
# To create an entry follow this format:
#
# '<main-keyword>' :
# synonymns :
# - '<synonymn1>'
# - '<synonymn2>'
# - '<synonymn3 ... >'
# synonyms :
# - '<synonym1>'
# - '<synonym2>'
# - '<synonym3 ... >'
# title: '<title for this term>'
# description :
# '<description of this term>'
Expand All @@ -32,11 +32,11 @@
# to avoid a keyword not being registered. When the user searches
# their entered keyword case will not matter.

'wic' :
synonymns :
- 'women, infants, and children'
- 'women, infants, & children'
- 'assistance for mothers'
wic :
synonyms :
- women, infants, and children
- women, infants, & children
- assistance for mothers
title: Women, Infants, and Children
description :
Women, Infants, and Children (WIC)
Expand All @@ -45,40 +45,40 @@
children up to age 5..
url : http://www.fns.usda.gov/wic

'sfmnp' :
synonymns :
- "senior farmers' market nutrition program"
- 'food vouchers for seniors'
- 'food vouchers'
title : "Senior Farmers' Market Nutrition Program"
sfmnp :
synonyms :
- senior farmers' market nutrition program
- food vouchers for seniors
- food vouchers
title : Senior Farmers' Market Nutrition Program
description :
"Senior Farmers' Market Nutrition Program (SFMNP)
Senior Farmers' Market Nutrition Program (SFMNP)
provides low-income seniors with coupons that can be exchanged for eligible
foods at farmers' markets, roadside stands, and community-supported
agriculture programs."
agriculture programs.
url : http://www.fns.usda.gov/sfmnp

'calfresh' :
synonymns :
- 'food stamps'
- 'snap'
calfresh :
synonyms :
- food stamps
- snap
title : CalFresh
description :
Known federally as SNAP (Supplemental Nutrition Assistance Program),
CalFresh offers nutrition assistance to eligible, low income individuals
and families and provides economic benefits to communities.
url : http://www.calfresh.ca.gov

'market match' :
synonymns : ''
market match :
synonyms : ''
title : Market Match
description :
"Market Match offers farmers’ market customers an extra $5 when they spend
at least $10 on their CalFresh EBT card at participating farmer's markets."
Market Match offers farmers’ market customers an extra $5 when they spend
at least $10 on their CalFresh EBT card at participating farmer's markets.
url : http://www.pcfma.com/pcfma_marketmatch.php

'health care reform':
synonymns :
- 'aca'
- 'affordable care act'
- 'health insurance'
health care reform:
synonyms :
- aca
- affordable care act
- health insurance
20 changes: 20 additions & 0 deletions config/test/terminology.yml
@@ -0,0 +1,20 @@
# Please don't change this file unless you know what you're doing.
# These values are needed in order for the tests to pass.
wic :
synonyms :
- women, infants, and children
- women, infants, & children
- assistance for mothers
title: Women, Infants, and Children
description :
Women, Infants, and Children (WIC)
provides assistance for low-income pregnant, breastfeeding, and
non-breastfeeding postpartum women, and to eligible infants and
children up to age 5..
url : http://www.fns.usda.gov/wic

health care reform :
synonyms :
- aca
- affordable care act
- health insurance

0 comments on commit 814b765

Please sign in to comment.