class WorldDb::ReaderBaseWithMoreAttribs

todo/fix:

try to merge ReaderBaseWithMoreAttribs and ReaderBaseWithOpts into one base - why? why not?

Public Class Methods

from_file( path, more_attribs={} ) click to toggle source
# File lib/worlddb/readers/base.rb, line 52
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/worlddb/readers/base.rb, line 59
def self.from_string( text, more_attribs={} )
  puts "[debug] ReaderBase.from_string calling #{self.name}.new"  # note: assume self is derived class (object)
  self.new( text, more_attribs )
end
from_zip( zip_file, entry_path, more_attribs={} ) click to toggle source
# File lib/worlddb/readers/base.rb, line 23
  def self.from_zip( zip_file, entry_path, more_attribs={} )
    ## get text content from zip

    entry = zip_file.find_entry( entry_path )

    ## todo/fix: add force encoding to utf-8 ??
    ##  check!!!
    ##  clean/prepprocess lines
    ##  e.g. CR/LF (/r/n) to LF (e.g. /n)
    text = entry.get_input_stream().read()

    ## NOTE: needs logger ref; only available in instance methods; use global logger for now
    logger = LogUtils::Logger.root
    logger.debug "text.encoding.name (before): #{text.encoding.name}"
#####
# NB: ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
## NB:
# for now "hardcoded" to utf8 - what else can we do?
# - note: force_encoding will NOT change the chars only change the assumed encoding w/o translation
    text = text.force_encoding( Encoding::UTF_8 )
    logger.debug "text.encoding.name (after): #{text.encoding.name}"     

    ## todo:
    # NB: for convenience: convert fancy unicode dashes/hyphens to plain ascii hyphen-minus
    ## text = TextUtils.convert_unicode_dashes_to_plain_ascii( text, path: path )

    self.from_string( text, more_attribs )
  end
new( text, more_attribs={} ) click to toggle source
# File lib/worlddb/readers/base.rb, line 68
def initialize( text, more_attribs={} )
  ## todo/fix: how to add opts={} ???

  @text         = text
  @more_attribs = more_attribs
end

Public Instance Methods

skip_tags?() click to toggle source
# File lib/worlddb/readers/base.rb, line 65
def skip_tags?()   @skip_tags == true;  end
strict?() click to toggle source
# File lib/worlddb/readers/base.rb, line 66
def strict?()      @strict == true;     end