class BeerDb::BreweryReader
Public Class Methods
from_file( path, more_attribs={} )
click to toggle source
# File lib/beerdb/readers/brewery.rb, line 23 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={} )
click to toggle source
# File lib/beerdb/readers/brewery.rb, line 30 def self.from_string( text, more_attribs={} ) BreweryReader.new( text, more_attribs ) end
from_zip( zip_file, entry_path, more_attribs={} )
click to toggle source
# File lib/beerdb/readers/brewery.rb, line 13 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
new( text, more_attribs={} )
click to toggle source
# File lib/beerdb/readers/brewery.rb, line 34 def initialize( text, more_attribs={} ) ## todo/fix: how to add opts={} ??? @text = text @more_attribs = more_attribs end
Public Instance Methods
read()
click to toggle source
# File lib/beerdb/readers/brewery.rb, line 43 def read() =begin if name =~ /\(m\)/ # check for (m) mid-size/medium marker -todo- use $?? must be last? more_attribs[ :prod_m ] = true elsif name =~ /\(l\)/ # check for (l) large marker - todo - use $?? must be last? more_attribs[ :prod_l ] = true else ## no marker; do nothing end =end reader = ValuesReader.from_string( @text, @more_attribs ) reader.each_line do |new_attributes, values| ####### # fix: move to (inside) # Brewery.create_or_update_from_attribs |||| ## note: group header not used for now; do NOT forget to remove from hash! if new_attributes[:header].present? logger.warn "removing unused group header #{new_attributes[:header]}" new_attributes.delete(:header) ## note: do NOT forget to remove from hash! end Brewery.create_or_update_from_attribs( new_attributes, values ) end # each_line end