Class: Tolk::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/tolk/export.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Export

Returns a new instance of Export.



5
6
7
8
9
# File 'lib/tolk/export.rb', line 5

def initialize(args)
  @name = args.fetch(:name, '')
  @data = args.fetch(:data, {})
  @destination = args.fetch(:destination, self.class.dump_path)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/tolk/export.rb', line 3

def data
  @data
end

#destinationObject (readonly)

Returns the value of attribute destination.



3
4
5
# File 'lib/tolk/export.rb', line 3

def destination
  @destination
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/tolk/export.rb', line 3

def name
  @name
end

Class Method Details

.dump(args) ⇒ Object



23
24
25
# File 'lib/tolk/export.rb', line 23

def dump(args)
  new(args).dump
end

.dump_pathObject



27
28
29
# File 'lib/tolk/export.rb', line 27

def dump_path
  Tolk::Locale._dump_path
end

Instance Method Details

#dumpObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/tolk/export.rb', line 11

def dump
  File.open("#{destination}/#{name}.yml", "w+") do |file|
    yml = if data.respond_to?(:ya2yaml)
      data.ya2yaml(:syck_compatible => true)
    else
      YAML.dump(data).force_encoding(file.external_encoding.name)
    end
    file.write(yml)
  end
end