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, line 182 def initialize(options = {}, prologue = {}, epilogue = {}, &block) super(options, &block) prologue[self.class::NAME] ||= options[:name] @prologue = self.class::PROLOGUE.merge(prologue) @epilogue = self.class::EPILOGUE.merge(epilogue) end
open(*args, &block)
click to toggle source
Calls superclass method
# File lib/midos/writer.rb, line 176 def open(*args, &block) super { |mth| mth.instruct!(&block) } end
write(*args, &block)
click to toggle source
# File lib/midos/writer.rb, line 171 def write(*args, &block) new(args.extract_options!, &block) .instruct! { |mth| mth.write(*args) } end
Public Instance Methods
instruct!(*args) { |self| ... }
click to toggle source
# File lib/midos/writer.rb, line 193 def instruct!(*args) put(prologue, *args) yield self put(epilogue, *args) end
Private Instance Methods
merge_records(hash, records, *args)
click to toggle source
# File lib/midos/writer.rb, line 201 def merge_records(hash, records, *args) args = [hash, records, *resolve_from_to(*args)] records.each { |id, record| new_record = hash[id] = {} record.each { |key, value| new_record[key] = resolve(key, value, *args) } } end
resolve(key, value, hash, records, from = nil, to = nil)
click to toggle source
# File lib/midos/writer.rb, line 219 def resolve(key, value, hash, records, from = nil, to = nil) from && from.include?(key) ? value.map { |id| records[id][to] } : value end
resolve_from_to(from = nil, to = prologue[RESOLVE_TO])
click to toggle source
# File lib/midos/writer.rb, line 212 def resolve_from_to(from = nil, to = prologue[RESOLVE_TO]) from = prologue.values_at(*RESOLVE_FROM) .map { |v| v.split('~').first } if from.nil? || from == true [from, to] end