Class: ContentReplacer

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

Instance Method Summary collapse

Constructor Details

#initialize(converter) ⇒ ContentReplacer

Returns a new instance of ContentReplacer.



5
6
7
8
9
10
11
# File 'lib/content_replacer.rb', line 5

def initialize(converter)
  @synthesize = converter.synthesize
  @properties = converter.properties
  @release    = converter.release
  @unload     = converter.unload
  @position_prop_after_closing_bracket = Configuration.settings['position_prop_after_closing_bracket']
end

Instance Method Details

#header_content(file_path) ⇒ Object

Reading and updating the .h file contents



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/content_replacer.rb', line 38

def header_content(file_path)
  if @position_prop_after_closing_bracket
    next_bracket = false
    hFileContents = IO.read(file_path)
    updatedHFileContents = ''
    hFileContents.split("\n").each do |line|
      next_bracket = true if line =~ /^@interface/

      if line =~ /^\}/ && next_bracket
        next_bracket = false
        updatedHFileContents << line + "\n" + @properties.chomp
      else
        updatedHFileContents << line
      end
      updatedHFileContents << "\n"
    end

  else

    next_bracket = false
    hFileContents = IO.read(file_path)
    updatedHFileContents = ''
    hFileContents.split("\n").each do |line|
      next_bracket = true if line =~ /^@interface/

      if line =~ /^\@end/ && next_bracket
        next_bracket = false
        updatedHFileContents << @properties.chomp + "\n" + line
      else
        updatedHFileContents << line
      end
      updatedHFileContents << "\n"
    end
  end
  updatedHFileContents
end

#m_content(file_path) ⇒ Object

Reading and updating the .m file contents



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

def m_content(file_path)
  mFileContents = IO.read(file_path)
  updatedFileContents = ''
  mFileContents.split("\n").each do |line|
    if line =~ /^@implementation/
      updatedFileContents << line + "\n" + @synthesize.chomp
    elsif line =~ /\[super dealloc\]/
      updatedFileContents << @release.chomp + "\n" + line
    elsif line =~ /\(void\)\s?viewDidUnload/
      updatedFileContents << line + "\n" + @unload.chomp
    else
      updatedFileContents << line
    end
    updatedFileContents << "\n"
  end

  updatedFileContents
end