Class: Xcplayground::XcplaygroundFile

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

Overview

Represent a Swift language file on disc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform, fname = 'contents.xcplayground', version = '5.0') ⇒ XcplaygroundFile

Returns a new instance of XcplaygroundFile.



10
11
12
13
14
# File 'lib/xcplayground/xcplayground_file.rb', line 10

def initialize(platform, fname = 'contents.xcplayground', version = '5.0')
  @platform = platform
  @filename = fname
  @version  = version
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



8
9
10
# File 'lib/xcplayground/xcplayground_file.rb', line 8

def filename
  @filename
end

#platformObject

Returns the value of attribute platform.



7
8
9
# File 'lib/xcplayground/xcplayground_file.rb', line 7

def platform
  @platform
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/xcplayground/xcplayground_file.rb', line 6

def version
  @version
end

Instance Method Details

#save(path, timeline_file = 'timeline.xctimeline') ⇒ Object



16
17
18
19
20
21
# File 'lib/xcplayground/xcplayground_file.rb', line 16

def save(path, timeline_file = 'timeline.xctimeline')
  file = File.join(path, filename)
  File.open(file, 'w') do |f|
    f.puts to_s(timeline_file)
  end
end

#to_s(timeline_file) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/xcplayground/xcplayground_file.rb', line 23

def to_s(timeline_file)
  xml = Builder::XmlMarkup.new(indent: 2)
  xml.instruct! :xml, version: '1.0', encoding: 'UTF-8', standalone: 'yes'
  xml.playground(version: version, 'target-platform' => platform) do |p|
    p.timeline(fileName: timeline_file)
  end
  xml.target!
end