Class: Rozi::NameSearchTextFile

Inherits:
FileWrapperBase show all
Defined in:
lib/rozi/name_search.rb

Overview

A thin layer above File that handles reading and writing of names to name search text files

Instance Attribute Summary

Attributes inherited from FileWrapperBase

#file

Instance Method Summary collapse

Methods inherited from FileWrapperBase

#close, #closed?, #initialize, open, #rewind

Constructor Details

This class inherits a constructor from Rozi::FileWrapperBase

Instance Method Details

#write(enumerable) ⇒ nil

Writes an enumerable of Rozi::Name objects to the file

Parameters:

  • enumerable (Enumerable)

Returns:

  • (nil)


72
73
74
75
76
77
78
# File 'lib/rozi/name_search.rb', line 72

def write(enumerable)
  enumerable.each { |name|
    write_name name
  }

  nil
end

#write_name(name) ⇒ nil

Note:

If no properties have been written to the file before this method is called, a default set of properties will be automatically written to the file first

Writes a Rozi::Name to the file

Parameters:

Returns:

  • (nil)


89
90
91
92
93
94
95
96
# File 'lib/rozi/name_search.rb', line 89

def write_name(name)
  ensure_properties

  @file.write serialize_name(name)
  @file.write "\n"

  nil
end

#write_properties(properties) ⇒ nil

Writes name search properties to the file

The file must be empty when this method is called!

Parameters:

Returns:

  • (nil)

Raises:

  • (RuntimeError)

    if the file isn’t empty



107
108
109
110
111
112
113
114
115
116
# File 'lib/rozi/name_search.rb', line 107

def write_properties(properties)
  if @file.size > 0
    raise "Can't write file properties, file is not empty"
  end

  @file.write serialize_properties(properties)
  @file.write "\n"

  nil
end