Sha256: 7d7d0626b5c106ef1448b2357d8fbd04a32daff67d995184f39fd3274cd2a780

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

# encoding: UTF-8

module SportDb


class GroundReader

  include LogUtils::Logging

## make models available by default with namespace
#  e.g. lets you use Usage instead of Model::Usage
  include Models

  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

  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

  def self.from_string( text, more_attribs={} )
    GroundReader.new( text, more_attribs )
  end  


  def initialize( text, more_attribs={} )
    ## todo/fix: how to add opts={} ???
    @text = text
    @more_attribs = more_attribs
  end


  def read( name, more_attribs={} )
    reader = ValuesReader.from_string( @text, @more_attribs )

    reader.each_line do |new_attributes, values|
      Ground.create_or_update_from_values( new_attributes, values )
    end # each lines
  end


end # class GroundReader
end # module SportDb

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
sportdb-models-1.11.0 lib/sportdb/readers/ground.rb
sportdb-models-1.10.1 lib/sportdb/readers/ground.rb
sportdb-models-1.10.0 lib/sportdb/readers/ground.rb
sportdb-1.9.16 lib/sportdb/readers/ground.rb
sportdb-1.9.15 lib/sportdb/readers/ground.rb
sportdb-1.9.14 lib/sportdb/readers/ground.rb
sportdb-1.9.13 lib/sportdb/readers/ground.rb
sportdb-1.9.12 lib/sportdb/readers/ground.rb
sportdb-1.9.11 lib/sportdb/readers/ground.rb