Class: SportDb::SeasonReader
- Inherits:
-
Object
- Object
- SportDb::SeasonReader
show all
- Includes:
- LogUtils::Logging, Model
- Defined in:
- lib/sportdb/readers/season.rb
Constant Summary
Constants included
from Model
Model::City, Model::Continent, Model::Country, Model::Person, Model::Prop, Model::Region
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SeasonReader.
37
38
39
40
|
# File 'lib/sportdb/readers/season.rb', line 37
def initialize( text )
@text = text
end
|
Class Method Details
.from_file(path) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/sportdb/readers/season.rb', line 25
def self.from_file( path )
text = File.read_utf8( path )
self.from_string( text )
end
|
.from_string(text) ⇒ Object
32
33
34
|
# File 'lib/sportdb/readers/season.rb', line 32
def self.from_string( text )
SeasonReader.new( text )
end
|
.from_zip(zip_file, entry_path) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/sportdb/readers/season.rb', line 15
def self.from_zip( zip_file, entry_path )
entry = zip_file.find_entry( entry_path )
text = entry.get_input_stream().read()
text = text.force_encoding( Encoding::UTF_8 )
self.from_string( text )
end
|
Instance Method Details
#read ⇒ Object
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
|
# File 'lib/sportdb/readers/season.rb', line 42
def read()
reader = LineReader.from_string( @text )
reader.each_line do |line|
logger.debug ">#{line}<"
key = line
logger.debug " find season key: #{key}"
season = Season.find_by_key( key )
season_attribs = {}
if season.present?
logger.debug "update season #{season.id}-#{season.key}:"
else
logger.debug "create season:"
season = Season.new
season_attribs[ :key ] = key
end
season_attribs[ :title ] = key
logger.debug season_attribs.to_json
season.update_attributes!( season_attribs )
end
end
|