class Midos::Writer::Thesaurus

Constants

EPILOGUE
NAME
PROLOGUE
RESOLVE_FROM
RESOLVE_TO

Attributes

epilogue[R]
prologue[R]

Public Class Methods

new(options = {}, prologue = {}, epilogue = {}, &block) click to toggle source
Calls superclass method
    # File lib/midos/writer.rb
183 def initialize(options = {}, prologue = {}, epilogue = {}, &block)
184   super(options, &block)
185 
186   prologue[self.class::NAME] ||= options[:name]
187 
188   @prologue = self.class::PROLOGUE.merge(prologue)
189   @epilogue = self.class::EPILOGUE.merge(epilogue)
190 end
open(*args, &block) click to toggle source
Calls superclass method
    # File lib/midos/writer.rb
177 def open(*args, &block)
178   super { |mth| mth.instruct!(&block) }
179 end
write(*args, &block) click to toggle source
    # File lib/midos/writer.rb
172 def write(*args, &block)
173   new(args.extract_options!, &block)
174     .instruct! { |mth| mth.write(*args) }
175 end

Public Instance Methods

instruct!(*args) { |self| ... } click to toggle source
    # File lib/midos/writer.rb
194 def instruct!(*args)
195   put(prologue, *args)
196   yield self
197   put(epilogue, *args)
198 end

Private Instance Methods

merge_records(hash, records, *args) click to toggle source
    # File lib/midos/writer.rb
202 def merge_records(hash, records, *args)
203   args = [hash, records, *resolve_from_to(*args)]
204 
205   records.each { |id, record|
206     new_record = hash[id] = {}
207 
208     record.each { |key, value|
209       new_record[key] = resolve(key, value, *args) }
210   }
211 end
resolve(key, value, hash, records, from = nil, to = nil) click to toggle source
    # File lib/midos/writer.rb
220 def resolve(key, value, hash, records, from = nil, to = nil)
221   from && from.include?(key) ? value.map { |id| records[id][to] } : value
222 end
resolve_from_to(from = nil, to = prologue[RESOLVE_TO]) click to toggle source
    # File lib/midos/writer.rb
213 def resolve_from_to(from = nil, to = prologue[RESOLVE_TO])
214   from = prologue.values_at(*RESOLVE_FROM)
215     .map { |v| v.split('~').first } if from.nil? || from == true
216 
217   [from, to]
218 end