Class: Converter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selection) ⇒ Converter

Returns a new instance of Converter.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/converter.rb', line 6

def initialize(selection)
  @properties  = ''
  @synthesize  = ''
  @release     = ''
  @unload      = ''
  @selection   = selection

  @copy          = Configuration.types['copy']
  @assign        = Configuration.types['assign']
  @use_nonatomic = Configuration.settings['use_nonatomic']
  @outlet        = Configuration.settings['outlet']
end

Instance Attribute Details

#propertiesObject

Returns the value of attribute properties.



4
5
6
# File 'lib/converter.rb', line 4

def properties
  @properties
end

#releaseObject

Returns the value of attribute release.



4
5
6
# File 'lib/converter.rb', line 4

def release
  @release
end

#synthesizeObject

Returns the value of attribute synthesize.



4
5
6
# File 'lib/converter.rb', line 4

def synthesize
  @synthesize
end

#unloadObject

Returns the value of attribute unload.



4
5
6
# File 'lib/converter.rb', line 4

def unload
  @unload
end

Instance Method Details

#convertObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/converter.rb', line 19

def convert
  @selection.split("\n").each do |line|
    line      = line.scan("*") == [] ? line.strip : line.gsub!(/\*/, '').strip
    words     = line.split(/\s+/)
    label     = words.size > 2 ? words[1] : words[0]
    variable  = words[-1]
    mem_label = memory_management(label)
    star      = mem_label == 'assign' ? '' : '*'

    @properties << "@property (#{use_nonatomic(mem_label)}) #{("IBOutlet " if @outlet)}#{label} #{star}#{variable}\n"
    @synthesize << "@synthesize #{variable}\n"
    @release    << "\tself.#{clean_var(variable)} = nil;\n" unless mem_label == 'assign'
    @unload     << "\tself.#{clean_var(variable)} = nil;\n"
  end
end