Class: SBConstants::SwiftConstantWriter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/sbconstants/swift_constant_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_source, swift_out) ⇒ SwiftConstantWriter

Returns a new instance of SwiftConstantWriter.



6
7
8
9
# File 'lib/sbconstants/swift_constant_writer.rb', line 6

def initialize data_source, swift_out
  super data_source
  @swift_out = swift_out
end

Instance Method Details

#template_with_file(head, body) ⇒ Object



21
22
23
24
25
26
# File 'lib/sbconstants/swift_constant_writer.rb', line 21

def template_with_file head, body
  @head = head
  @body = body
  pre_processed_template = ERB.new(File.open("#{templates_dir}swift_body.erb").read, nil, '<>').result(binding)
  ERB.new(pre_processed_template, nil, '<>').result(binding)
end

#templates_dirObject



17
18
19
# File 'lib/sbconstants/swift_constant_writer.rb', line 17

def templates_dir
  @templates_dir ||= File.dirname(__FILE__) + '/templates/'
end

#writeObject



11
12
13
14
15
# File 'lib/sbconstants/swift_constant_writer.rb', line 11

def write
  head = %Q{\nimport Foundation"\n}
  body = %Q{    case <%= sanitise_key(constant) %> = "<%= constant %>"\n}
  @swift_out.puts template_with_file head, body
end