Module: ActiveNutrition
- Defined in:
- lib/active_nutrition.rb,
lib/active_nutrition/models.rb,
lib/active_nutrition/objects.rb,
lib/active_nutrition/railtie.rb,
lib/active_nutrition/version.rb,
lib/active_nutrition/utilities.rb,
lib/active_nutrition/objects/base.rb,
lib/active_nutrition/objects/food.rb,
lib/active_nutrition/models/src_cd.rb,
lib/active_nutrition/models/weight.rb,
lib/active_nutrition/models/langual.rb,
lib/active_nutrition/objects/weight.rb,
lib/active_nutrition/models/data_src.rb,
lib/active_nutrition/models/datsrcln.rb,
lib/active_nutrition/models/deriv_cd.rb,
lib/active_nutrition/models/fd_group.rb,
lib/active_nutrition/models/food_des.rb,
lib/active_nutrition/models/footnote.rb,
lib/active_nutrition/models/langdesc.rb,
lib/active_nutrition/models/nut_data.rb,
lib/active_nutrition/models/nutr_def.rb,
lib/active_nutrition/objects/weights.rb,
lib/active_nutrition/models/migration.rb,
lib/active_nutrition/utilities/update.rb,
lib/active_nutrition/objects/food_group.rb,
lib/active_nutrition/utilities/data_file.rb,
lib/active_nutrition/objects/nutrition_fact.rb,
lib/active_nutrition/objects/nutrition_facts.rb,
lib/active_nutrition/utilities/unit_converter.rb,
lib/active_nutrition/migrations/00000000002_sr_24.rb,
lib/active_nutrition/migrations/00000000001_migrations_table.rb
Defined Under Namespace
Modules: Migrations, Models, Objects, Utilities
Classes: Railtie
Constant Summary
collapse
- DEFAULT_SEARCH_LIMIT =
10
- VERSION =
"0.6.0"
- USDA_VERSION =
"24"
Class Method Summary
collapse
Class Method Details
.convert(value, options = {}) ⇒ Object
76
77
78
|
# File 'lib/active_nutrition.rb', line 76
def convert(value, options = {})
UnitConverter.convert(value, options)
end
|
.get(ndb_no) ⇒ Object
72
73
74
|
# File 'lib/active_nutrition.rb', line 72
def get(ndb_no)
Food.wrap(FoodDes.find(ndb_no))
end
|
.migrate ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/active_nutrition.rb', line 34
def migrate
current_migrations = Migration.find(:all).map(&:sequence_no)
rescue ActiveRecord::StatementInvalid => e
ActiveNutrition::Migrations::MigrationsTable.up
Migration.create(:sequence_no => 1)
current_migrations = Migration.find(:all).map(&:sequence_no)
ensure
next_migrations = migrations.reject { |file| (current_migrations || []).include?(File.basename(file)[0..11].to_i) }.sort
next_migrations.each do |file|
require file
migration_class = ActiveNutrition::Migrations.const_get(File.basename(file).split("_")[1..-1].map(&:capitalize).join("").chomp(".rb"))
migration_class.up
Migration.create(:sequence_no => File.basename(file)[0..11].to_i)
end
end
|
.rebuild ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/active_nutrition.rb', line 54
def rebuild
upd = Update.new(:type => :full)
puts "Downloading data..."
upd.download
puts "Extracting..."
upd.unzip
puts "Clearing tables..."
upd.reset_db
execute_update(upd)
puts "\nDone."
end
|
.search(terms = "", options = {}) ⇒ Object
66
67
68
69
70
|
# File 'lib/active_nutrition.rb', line 66
def search(terms = "", options = {})
options[:conditions] ||= ["Long_Desc LIKE ? OR Long_Desc LIKE ?", "%#{terms.gsub(" ", "%")}%", "%#{terms.split(" ").reverse.join("%")}%"]
options[:limit] ||= DEFAULT_SEARCH_LIMIT
Food.wrap(FoodDes.find(:all, options))
end
|
.supported_conversion?(options) ⇒ Boolean
.update ⇒ Object
50
51
52
|
# File 'lib/active_nutrition.rb', line 50
def update
raise "Not yet supported."
end
|