Class: SportDB::Reader
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(logger = nil) ⇒ Reader
constructor
A new instance of Reader.
-
#load_fixtures_builtin(event_key, name) ⇒ Object
load from gem (built-in).
-
#load_fixtures_with_include_path(event_key, name, include_path) ⇒ Object
load from file system.
- #run(opts, args) ⇒ Object
Constructor Details
#initialize(logger = nil) ⇒ Reader
Returns a new instance of Reader.
10 11 12 13 14 15 16 17 |
# File 'lib/sportdb/reader.rb', line 10 def initialize( logger=nil ) if logger.nil? @logger = Logger.new(STDOUT) @logger.level = Logger::INFO else @logger = logger end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
19 20 21 |
# File 'lib/sportdb/reader.rb', line 19 def logger @logger end |
Instance Method Details
#load_fixtures_builtin(event_key, name) ⇒ Object
load from gem (built-in)
46 47 48 49 50 51 52 53 54 |
# File 'lib/sportdb/reader.rb', line 46 def load_fixtures_builtin( event_key, name ) # load from gem (built-in) path = "#{SportDB.root}/db/#{name}.txt" puts "*** parsing data '#{name}' (#{path})..." code = File.read( path ) load_fixtures_worker( event_key, code ) end |
#load_fixtures_with_include_path(event_key, name, include_path) ⇒ Object
load from file system
36 37 38 39 40 41 42 43 44 |
# File 'lib/sportdb/reader.rb', line 36 def load_fixtures_with_include_path( event_key, name, include_path ) # load from file system path = "#{include_path}/#{name}.txt" puts "*** parsing data '#{name}' (#{path})..." code = File.read( path ) load_fixtures_worker( event_key, code ) end |
#run(opts, args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sportdb/reader.rb', line 21 def run( opts, args ) args.each do |arg| name = arg # File.basename( arg, '.*' ) if opts.load? load_fixtures_builtin( opts.event, name ) else load_fixtures_with_include_path( opts.event, name, opts.data_path ) end end end |