Class: Shift::String

Inherits:
String
  • Object
show all
Includes:
Transformable
Defined in:
lib/shift/string.rb

Overview

String result from one of the operations. Extends string with some useful helper methods to write to disk, do further transformations etc, allowing chaining of operations.

Instance Attribute Summary

Attributes included from Transformable

#name

Instance Method Summary collapse

Methods included from Transformable

#can?, #interface, #method_missing, #process, #respond_to?

Constructor Details

#initialize(str = '', name = nil) ⇒ Shift::String

Create a new shift string from a standard string.



97
98
99
100
# File 'lib/shift/string.rb', line 97

def initialize(str='', name=nil)
  super(str)
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Shift::Transformable

Instance Method Details

#dataObject



102
103
104
# File 'lib/shift/string.rb', line 102

def data
  self
end

#read_append(path) ⇒ Object Also known as: append_read

Read a file and append its contents.



108
109
110
111
# File 'lib/shift/string.rb', line 108

def read_append(path)
  data << File.read(path)
  self
end

#write(name_override = nil) ⇒ Object

Write the string to a sepcified path. @ return self



116
117
118
119
120
# File 'lib/shift/string.rb', line 116

def write(name_override=nil)
  path = name_override || name || name_error
  File.open(path, 'w') {|f| f.write(data) }
  self
end