Module: Cosing

Defined in:
lib/cosing.rb,
lib/cosing/annex.rb,
lib/cosing/types.rb,
lib/cosing/parser.rb,
lib/cosing/annex/v.rb,
lib/cosing/version.rb,
lib/cosing/annex/ii.rb,
lib/cosing/annex/iv.rb,
lib/cosing/annex/vi.rb,
lib/cosing/database.rb,
lib/cosing/patterns.rb,
lib/cosing/annex/iii.rb,
lib/cosing/annex/base.rb,
lib/cosing/annex/rule.rb,
lib/cosing/ingredient.rb,
lib/cosing/annex/sccs_opinion.rb

Defined Under Namespace

Modules: Annex, Parser, Patterns, Types Classes: Database, Error, Ingredient

Constant Summary collapse

GEM_ROOT =
File.expand_path("..", __dir__)
VERSION =
"0.3.2"

Class Method Summary collapse

Class Method Details

.gem_path(path) ⇒ Object



43
44
45
# File 'lib/cosing.rb', line 43

def gem_path(path)
  Pathname.new(GEM_ROOT).join(path)
end

.loadObject

Your code goes here…



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cosing.rb', line 24

def load
  Database.new(Annex.load).tap do |database|
    path = gem_path("data/ingredients.csv")
    ingredient_file = File.read(path).delete("\r")

    CSV.parse(
      ingredient_file,
      headers: true,
      liberal_parsing: true,
      header_converters: :symbol
    ) do |row|
      row
        .to_h
        .transform_values! { |value| value.to_s.strip }
        .then { |row| database.add_ingredient(row) }
    end
  end
end