Class: Swift::Playground::Asset
- Inherits:
-
Object
- Object
- Swift::Playground::Asset
- Includes:
- Util::SourceIO
- Defined in:
- lib/swift/playground/asset.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
- #filename(number) ⇒ Object
-
#initialize(content, options = {}) ⇒ Asset
constructor
A new instance of Asset.
- #save(destination_path, number) ⇒ Object
Methods included from Util::SourceIO
#derived_filename, #source_as_io
Constructor Details
#initialize(content, options = {}) ⇒ Asset
Returns a new instance of Asset.
21 22 23 24 25 26 27 |
# File 'lib/swift/playground/asset.rb', line 21 def initialize(content, = {}) pathname_or_content = source_as_io(content) self.content = pathname_or_content.read filename = [:filename] || derived_filename(pathname_or_content) @filename = filename || default_filename end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
19 20 21 |
# File 'lib/swift/playground/asset.rb', line 19 def content @content end |
Instance Method Details
#filename(number) ⇒ Object
29 30 31 |
# File 'lib/swift/playground/asset.rb', line 29 def filename(number) @filename % number end |
#save(destination_path, number) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/swift/playground/asset.rb', line 33 def save(destination_path, number) destination_path = Pathname.new(destination_path) = filename(number) path = destination_path.join() FileUtils.mkdir_p path.dirname path.open('w') do |file| file.write content end end |