Module: SmartCsvImport::Matchable::ClassMethods
- Defined in:
- lib/smart_csv_import/matchable.rb
Instance Method Summary collapse
- #csv_context(value = nil) ⇒ Object
- #csv_field(name, description:, required: false) ⇒ Object
- #csv_fields ⇒ Object
-
#csv_source(value = nil) ⇒ Object
Optional context that enriches the LLM matching prompt.
- #inherited(subclass) ⇒ Object
- #matching_strategy ⇒ Object
- #matching_strategy=(strategy) ⇒ Object
- #required_csv_fields ⇒ Object
Instance Method Details
#csv_context(value = nil) ⇒ Object
53 54 55 |
# File 'lib/smart_csv_import/matchable.rb', line 53 def csv_context(value = nil) value ? @csv_context = value : @csv_context end |
#csv_field(name, description:, required: false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/smart_csv_import/matchable.rb', line 12 def csv_field(name, description:, required: false) name = name.to_sym raise ConfigurationError, "#{name} is not a declared attribute on #{self}" unless _has_attribute?(name) raise ConfigurationError, "#{name} is already declared as a csv_field" if csv_fields.key?(name) raise ConfigurationError, "description must be non-empty for #{name}" if description.to_s.strip.empty? csv_fields[name] = CsvFieldDefinition.new( name: name, description: description, required: required ) end |
#csv_fields ⇒ Object
26 27 28 |
# File 'lib/smart_csv_import/matchable.rb', line 26 def csv_fields @csv_fields ||= {} end |
#csv_source(value = nil) ⇒ Object
Optional context that enriches the LLM matching prompt. Both act as getter (no arg) and setter (with arg):
csv_source "ADP Workforce payroll export"
csv_context "HR platform for staffing agencies"
Source describes where the CSV comes from (system/tool). Context describes the business domain of the importing app. Together they let the LLM disambiguate headers like “Cell” or “Sal” that are genuinely ambiguous without domain knowledge.
49 50 51 |
# File 'lib/smart_csv_import/matchable.rb', line 49 def csv_source(value = nil) value ? @csv_source = value : @csv_source end |
#inherited(subclass) ⇒ Object
30 31 32 33 |
# File 'lib/smart_csv_import/matchable.rb', line 30 def inherited(subclass) super subclass.instance_variable_set(:@csv_fields, csv_fields.dup) end |
#matching_strategy ⇒ Object
57 58 59 |
# File 'lib/smart_csv_import/matchable.rb', line 57 def matching_strategy @matching_strategy end |
#matching_strategy=(strategy) ⇒ Object
61 62 63 |
# File 'lib/smart_csv_import/matchable.rb', line 61 def matching_strategy=(strategy) @matching_strategy = strategy end |
#required_csv_fields ⇒ Object
35 36 37 |
# File 'lib/smart_csv_import/matchable.rb', line 35 def required_csv_fields csv_fields.select { |_, field| field.required }.keys end |