Class: PersonDb::PersonReader
- Inherits:
-
Object
- Object
- PersonDb::PersonReader
- Includes:
- LogUtils::Logging, Models
- Defined in:
- lib/persondb/reader.rb
Class Method Summary collapse
- .from_file(path, more_attribs = {}) ⇒ Object
- .from_string(text, more_attribs = {}) ⇒ Object
- .from_zip(zip_file, entry_path, more_attribs = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(text, more_attribs = {}) ⇒ PersonReader
constructor
A new instance of PersonReader.
- #read ⇒ Object
Constructor Details
#initialize(text, more_attribs = {}) ⇒ PersonReader
Returns a new instance of PersonReader.
37 38 39 40 41 |
# File 'lib/persondb/reader.rb', line 37 def initialize( text, more_attribs={} ) ## todo/fix: how to add opts={} ??? @text = text @more_attribs = more_attribs end |
Class Method Details
.from_file(path, more_attribs = {}) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/persondb/reader.rb', line 25 def self.from_file( path, more_attribs={} ) ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark) ## - see textutils/utils.rb text = File.read_utf8( path ) self.from_string( text, more_attribs ) end |
.from_string(text, more_attribs = {}) ⇒ Object
32 33 34 |
# File 'lib/persondb/reader.rb', line 32 def self.from_string( text, more_attribs={} ) PersonReader.new( text, more_attribs ) end |
.from_zip(zip_file, entry_path, more_attribs = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/persondb/reader.rb', line 15 def self.from_zip( zip_file, entry_path, more_attribs={} ) ## get text content from zip entry = zip_file.find_entry( entry_path ) text = entry.get_input_stream().read() text = text.force_encoding( Encoding::UTF_8 ) self.from_string( text, more_attribs ) end |
Instance Method Details
#read ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/persondb/reader.rb', line 43 def read reader = ValuesReader.from_string( @text, @more_attribs ) reader.each_line do |new_attributes, values| Person.create_or_update_from_values( new_attributes, values ) end # each lines end |