Module: NDB

Defined in:
lib/ndb-ruby.rb,
lib/ndb/list.rb,
lib/ndb/search.rb,
lib/ndb/version.rb,
lib/ndb/food_report.rb,
lib/ndb/nutrient_report.rb

Defined Under Namespace

Classes: FoodReport, List, NutrientReport, Search

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.api_keyObject



12
13
14
# File 'lib/ndb-ruby.rb', line 12

def self.api_key
  @api_key
end

.api_key=(key) ⇒ Object



16
17
18
# File 'lib/ndb-ruby.rb', line 16

def self.api_key=(key)
  @api_key = key
end

.base_uriObject



20
21
22
# File 'lib/ndb-ruby.rb', line 20

def self.base_uri
  "http://api.nal.usda.gov/ndb"
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (NDB)

    the object that the method was called on



8
9
10
# File 'lib/ndb-ruby.rb', line 8

def self.configure
  yield self
end

.params_from_hash(hash) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ndb-ruby.rb', line 28

def self.params_from_hash(hash)
  hash.map do |param|
    param_list = []
    if param.last.is_a?(Array)
      param.last.each do |p|
        param_list << "nutrients=#{p}"
      end
    else
      param_list << "#{param.first}=#{param.last}"
    end
    param_list.join("&")
  end.join("&")
end

.sanitize_options(options, permitted_params) ⇒ Object



24
25
26
# File 'lib/ndb-ruby.rb', line 24

def self.sanitize_options(options, permitted_params)
  options.select { |param| permitted_params.include?(param.to_s) }
end