Class: SourceFileReaderWriter
- Inherits:
-
Object
- Object
- SourceFileReaderWriter
- Defined in:
- app/models/utils/sourcefilereader.rb
Overview
#<snip>
def any_oranges?
!@oranges.empty?
end
#</snip>
Instance Attribute Summary collapse
-
#file_to_open ⇒ Object
readonly
Returns the value of attribute file_to_open.
Class Method Summary collapse
Instance Method Summary collapse
- #convert_to_array_of_lines ⇒ Object
-
#initialize(file_to_open) ⇒ SourceFileReaderWriter
constructor
A new instance of SourceFileReaderWriter.
- #overwrite ⇒ Object
- #overwrite_existing_snips ⇒ Object
- #rewrite_whole_file ⇒ Object
Constructor Details
#initialize(file_to_open) ⇒ SourceFileReaderWriter
Returns a new instance of SourceFileReaderWriter.
21 22 23 24 25 |
# File 'app/models/utils/sourcefilereader.rb', line 21 def initialize(file_to_open) @@file_to_open = file_to_open @array_of_lines = [] @overwrite = [] end |
Instance Attribute Details
#file_to_open ⇒ Object (readonly)
Returns the value of attribute file_to_open.
15 16 17 |
# File 'app/models/utils/sourcefilereader.rb', line 15 def file_to_open @file_to_open end |
Class Method Details
.file_to_open ⇒ Object
17 18 19 |
# File 'app/models/utils/sourcefilereader.rb', line 17 def self.file_to_open @@file_to_open end |
Instance Method Details
#convert_to_array_of_lines ⇒ Object
27 28 29 30 31 32 |
# File 'app/models/utils/sourcefilereader.rb', line 27 def convert_to_array_of_lines File.open(@@file_to_open, "r").each do |line| @array_of_lines << line end @array_of_lines end |
#overwrite ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/utils/sourcefilereader.rb', line 42 def overwrite @overwrite.each_with_index do |element, index| if element.include?('<snip>') || element.include?('<$>') @overwrite[index].sub!(/<snip>/,'<*snip*>') @overwrite[index].sub!(/<\$>/,'<*$*>') end if element.include?('</snip>') || element.include?('</$>') @overwrite[index].sub!(/<\/snip>/,'</*snip*>') @overwrite[index].sub!(/<\/\$>/,'</*$*>') end end end |
#overwrite_existing_snips ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/utils/sourcefilereader.rb', line 34 def overwrite_existing_snips File.open(@@file_to_open, "r+").each do |line| @overwrite << line end overwrite rewrite_whole_file end |
#rewrite_whole_file ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/models/utils/sourcefilereader.rb', line 55 def rewrite_whole_file File.open(@@file_to_open, "w") do |file| @overwrite.each do |line| file << line end end end |