class Magnifier::Exporter

Attributes

magnifier_object[R]
path_object[R]

Public Class Methods

export(path_object, magnifier_object) click to toggle source
# File lib/magnifier/exporter.rb, line 7
def self.export(path_object, magnifier_object)
  new(path_object, magnifier_object).export
end
new(path_object, magnifier_object) click to toggle source
# File lib/magnifier/exporter.rb, line 11
def initialize(path_object, magnifier_object)
  @path_object = path_object
  @magnifier_object = magnifier_object
end

Public Instance Methods

export() click to toggle source
# File lib/magnifier/exporter.rb, line 16
def export
  file = File.open(@path_object, 'w')
  file.write(compose_yaml)
  file.close

  file
end

Private Instance Methods

compose_yaml() click to toggle source
# File lib/magnifier/exporter.rb, line 26
def compose_yaml
  result = {}
  @magnifier_object.instance_variables.each do |var_name|
    value = @magnifier_object.instance_variable_get(var_name)
    value = value.to_a if value.respond_to?(:to_a) # convert martixes to arrays

    result[var_name.to_s.slice(1..-1)] = value
  end

  result.to_yaml
end