Class: ActsAsCalculator::ImportDefinitions
- Inherits:
-
Object
- Object
- ActsAsCalculator::ImportDefinitions
- Defined in:
- lib/acts_as_calculator/import_definitions.rb
Overview
The one place import happens. Both authoring paths — the generator and the rake task — are argument parsing and printing around this call, so neither can drift into having its own idea of what "already imported" means.
Constant Summary collapse
- SECTIONS =
Lookup tables first: a formula version's variables name tables that have to resolve before a calculation using them can run.
{ "lookup_tables" => ImportLookupTable, "formulas" => ImportFormula, "templates" => ImportTemplate }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(path: nil, data: nil) ⇒ ImportDefinitions
constructor
A new instance of ImportDefinitions.
Constructor Details
#initialize(path: nil, data: nil) ⇒ ImportDefinitions
Returns a new instance of ImportDefinitions.
20 21 22 23 24 25 26 |
# File 'lib/acts_as_calculator/import_definitions.rb', line 20 def initialize(path: nil, data: nil) raise ImportError, "give ImportDefinitions either a path or data, not both" if path && data raise ImportError, "ImportDefinitions needs a path or data" if path.nil? && data.nil? @path = path @document = (data || ReadImportFile.(path)).transform_keys(&:to_s) end |
Class Method Details
.call ⇒ Object
16 17 18 |
# File 'lib/acts_as_calculator/import_definitions.rb', line 16 def self.call(...) new(...).call end |
Instance Method Details
#call ⇒ Object
28 29 30 31 32 |
# File 'lib/acts_as_calculator/import_definitions.rb', line 28 def call reject_unknown_sections ImportSummary.new(source: path&.to_s || "inline data", outcomes:) end |