<commit_before># encoding: utf-8

module SportDB

class Reader

## make models available in sportdb module by default with namespace
#  e.g. lets you use Team instead of Models::Team 
  include SportDB::Models


  def initialize( logger=nil )
    if logger.nil?
      @logger = Logger.new(STDOUT)
      @logger.level = Logger::INFO
    else
      @logger = logger
    end
  end

  attr_reader :logger

  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
<commit_msg>add load_fixtures_from_string<commit_after># encoding: utf-8

module SportDB


##
## fix/todo: move to/merge into LineReader itself

class StringLineReader

  def initialize( logger=nil, data )
    if logger.nil?
      @logger = Logger.new(STDOUT)
      @logger.level = Logger::INFO
    else
      @logger = logger
    end
    
    @data = data
  end

  attr_reader :logger


  def each_line
    @data.each_line do |line|
  
      if line =~ /^\s*#/
        # skip komments and do NOT copy to result (keep comments secret!)
        logger.debug 'skipping comment line'
        next
      end
        
      if line =~ /^\s*$/ 
        # kommentar oder leerzeile überspringen 
        logger.debug 'skipping blank line'
        next
      end

      # remove leading and trailing whitespace
      line = line.strip
 
      yield( line )
    end # each lines
  end # method each_line

end


class Reader

## make models available in sportdb module by default with namespace
#  e.g. lets you use Team instead of Models::Team 
  include SportDB::Models


  def initialize( logger=nil )
    if logger.nil?
      @logger = Logger.new(STDOUT)
      @logger.level = Logger::INFO
    else
      @logger = logger
    end
  end

  attr_reader :logger

  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


  def load_fixtures_from_string( event_key, text )  # load from string (e.g. passed in via web form)

    ## todo/fix: move code into LineReader e.g. use LineReader.fromString() - why? why not?
    reader = StringLineReader.new( logger, text )
    
    load_fixtures_worker( event_key, reader )

    ## fix add prop 
    ### Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )  
  end
{'fraction_non_alphanumeric': 0.09585975382320029, 'fraction_numerical': 0.0007459903021260724, 'mean_word_length': 2.3949367088607594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2719342', 'n_tokens_mistral': 890, 'n_tokens_neox': 849, 'n_words': 256}