Class: Ovaltine::StoryboardFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/ovaltine/objc/storyboard_formatter.rb

Constant Summary collapse

CELL_REUSE_SECTION_TITLE =
'Cell Reuse Identifiers'
SEGUE_SECTION_TITLE =
'Segue Identifiers'
VIEW_CONTROLLER_SECTION_TITLE =
'View Controllers'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storyboard, prefix, copyright, output_path) ⇒ StoryboardFormatter

Returns a new instance of StoryboardFormatter.



10
11
12
13
14
15
16
17
18
# File 'lib/ovaltine/objc/storyboard_formatter.rb', line 10

def initialize storyboard, prefix, copyright, output_path
  scrubbed_name = storyboard.name.gsub(/\W/,'_')
  @storyboard = storyboard
  @prefix = prefix
  @classname = "#{@prefix}#{scrubbed_name}Storyboard"
  @copyright = copyright
  @header_path = File.join(File.expand_path(output_path), "#{classname}.h")
  @impl_path = File.join(File.expand_path(output_path), "#{classname}.m")
end

Instance Attribute Details

#classnameObject (readonly)

Returns the value of attribute classname.



4
5
6
# File 'lib/ovaltine/objc/storyboard_formatter.rb', line 4

def classname
  @classname
end

#storyboardObject (readonly)

Returns the value of attribute storyboard.



4
5
6
# File 'lib/ovaltine/objc/storyboard_formatter.rb', line 4

def storyboard
  @storyboard
end

Instance Method Details



33
34
35
36
37
38
39
# File 'lib/ovaltine/objc/storyboard_formatter.rb', line 33

def copyright_text
  if @copyright.length > 0
    "Copyright (c) #{Time.new.year} #{@copyright}. All rights reserved."
  else
    ''
  end
end

#output_pathsObject



20
21
22
# File 'lib/ovaltine/objc/storyboard_formatter.rb', line 20

def output_paths
  [@header_path, @impl_path]
end

#writeObject



24
25
26
27
28
29
30
31
# File 'lib/ovaltine/objc/storyboard_formatter.rb', line 24

def write
  File.open(@header_path, 'w') do |file|
    file.puts generate_header
  end
  File.open(@impl_path, 'w') do |file|
    file.puts generate_implementation
  end
end