Class: Traitorous::Converter
- Inherits:
-
Object
- Object
- Traitorous::Converter
- Defined in:
- lib/traitorous/converter.rb
Overview
The purpose of the converters are to facilitate the importation of simple
JSON or YAML, CSV data, and import that data into an arbitrarily nested
tree of objects. And then to take those object and be able to export
that data in a simple form ready to save, that is functionally identical to
opts = {some: 'deep', data: ['structures']}
r = Mission.new(opts)
Mission.new(r.export) == r
Instance Attribute Summary collapse
-
#converters ⇒ Object
if no other converter is declared, use the identity converter which merely pass through the data passed to it.
-
#exporter ⇒ Object
if no other converter is declared, use the identity converter which merely pass through the data passed to it.
-
#importer ⇒ Object
if no other converter is declared, use the identity converter which merely pass through the data passed to it.
Instance Method Summary collapse
- #export(data) ⇒ Object
- #import(data) ⇒ Object
-
#initialize(importer, exporter = StandardProcs.noop) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(importer, exporter = StandardProcs.noop) ⇒ Converter
Returns a new instance of Converter.
17 18 19 20 |
# File 'lib/traitorous/converter.rb', line 17 def initialize(importer, exporter = StandardProcs.noop) @importer = importer @exporter = exporter end |
Instance Attribute Details
#converters ⇒ Object
if no other converter is declared, use the identity converter which merely pass through the data passed to it. DEFAULT_PROC is a default pass through proc
15 16 17 |
# File 'lib/traitorous/converter.rb', line 15 def converters @converters end |
#exporter ⇒ Object
if no other converter is declared, use the identity converter which merely pass through the data passed to it. DEFAULT_PROC is a default pass through proc
15 16 17 |
# File 'lib/traitorous/converter.rb', line 15 def exporter @exporter end |
#importer ⇒ Object
if no other converter is declared, use the identity converter which merely pass through the data passed to it. DEFAULT_PROC is a default pass through proc
15 16 17 |
# File 'lib/traitorous/converter.rb', line 15 def importer @importer end |
Instance Method Details
#export(data) ⇒ Object
26 27 28 |
# File 'lib/traitorous/converter.rb', line 26 def export(data) exporter.call(data) end |
#import(data) ⇒ Object
22 23 24 |
# File 'lib/traitorous/converter.rb', line 22 def import(data) importer.call(data) end |