Class: SBConstants::SwiftConstantWriter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SBConstants::SwiftConstantWriter
- Defined in:
- lib/sbconstants/swift_constant_writer.rb
Instance Method Summary collapse
-
#initialize(data_source, swift_out) ⇒ SwiftConstantWriter
constructor
A new instance of SwiftConstantWriter.
- #template_with_file(head, body) ⇒ Object
- #templates_dir ⇒ Object
- #write ⇒ Object
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_dir ⇒ Object
17 18 19 |
# File 'lib/sbconstants/swift_constant_writer.rb', line 17 def templates_dir @templates_dir ||= File.dirname(__FILE__) + '/templates/' end |
#write ⇒ Object
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 |