Class: SportDb::TeamIndexer
- Inherits:
-
Object
- Object
- SportDb::TeamIndexer
- Includes:
- LogUtils::Logging, Models
- Defined in:
- lib/sportdb/indexers/team.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text, more_attribs = {}) ⇒ TeamIndexer
constructor
A new instance of TeamIndexer.
- #read ⇒ Object
Constructor Details
#initialize(text, more_attribs = {}) ⇒ TeamIndexer
Returns a new instance of TeamIndexer.
31 32 33 34 35 |
# File 'lib/sportdb/indexers/team.rb', line 31 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
20 21 22 23 24 25 |
# File 'lib/sportdb/indexers/team.rb', line 20 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
27 28 29 |
# File 'lib/sportdb/indexers/team.rb', line 27 def self.from_string( text, more_attribs={} ) self.new( text, more_attribs ) end |
Instance Method Details
#read ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sportdb/indexers/team.rb', line 38 def read ## return a hash (with all records) e.g. ## {"austria"=> ## {:title=>"FK Austria Wien", ## :synonyms=>["Austria Wien", "Austria"], ## :values=> ## ["1911", ## "AUS", ## "www.fk-austria.at", ## "Fischhofgasse 12 // 1100 Wien", ## "city:wien"]}, ## "rapid"=> ## {:title=>"SK Rapid Wien", ## :synonyms=>["Rapid Wien", "Rapid"], ## :values=> ## ["1899", ## "RAP", ## "www.skrapid.at", ## "Keisslergasse 3 // 1140 Wien", ## "city:wien"]}, ## ... reader = ValuesReader.from_string( @text, @more_attribs ) h = {} reader.each_line do |new_attributes, values| puts "attribs:" pp new_attributes key = new_attributes.delete( :key ) ## remove key ## turn synonyms into an array synonyms = new_attributes[ :synonyms ] if synonyms new_attributes[ :synonyms ] = synonyms.split('|') end new_attributes[ :values ] = values h[ key ] = new_attributes end # each lines h ## return hash with all records (indexed by key) end |