Class: TaliaCore::DataTypes::SimpleText

Inherits:
FileRecord show all
Defined in:
lib/talia_core/data_types/simple_text.rb

Instance Attribute Summary

Attributes inherited from DataRecord

#temp_path

Instance Method Summary collapse

Methods inherited from FileRecord

#all_bytes, #get_byte, #position, #reset, #seek, #size

Methods included from PathHelpers::ClassMethods

#data_path, #tempfile_path

Methods included from DataLoader::ClassMethods

#create_from_url

Methods included from IipLoader

#convert_original?, #create_from_files, #create_from_stream, #create_iip, #open_original_image, #open_original_image_file, #open_original_image_stream, #orig_location, #prepare_image_from_existing!

Methods included from TaliaUtil::IoHelper

#base_for, #file_url, #open_from_url, #open_generic

Methods included from PathHelpers

#data_directory, #data_path, #extract_filename, #file_path, #full_filename, #static_path, #tempfile_path

Methods included from FileStore

#all_text, #assign_type, #create_from_data, #create_from_file, #is_file_open?, #write_file_after_save

Methods inherited from DataRecord

#all_bytes, #content_string, find_by_type_and_location!, find_data_records, #get_byte, #mime_type, #position, #reset, #seek, #size

Instance Method Details

#extract_mime_type(location) ⇒ Object

The MIME type is always text/plain



10
11
12
# File 'lib/talia_core/data_types/simple_text.rb', line 10

def extract_mime_type(location)
  'text/plain'
end

#get_line(close_after_single_read = false) ⇒ Object

Read onle line from the text file. The file will be closed if the end of the file is hit, or if close_after_single_read is set to true



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/talia_core/data_types/simple_text.rb', line 17

def get_line(close_after_single_read=false)
  if !is_file_open?
    open_file
  end

  # get a new line and return nil is EOF
  line = @file_handle.gets

  if line == nil or close_after_single_read
    close_file
  end

  # update the position of reading cursors
  @position += line.length

  return line
end