<commit_before>module CatchNotes
  class Image
    
    def initialize(opts)
      @attr = opts
      @url = nil
      @data = nil
      if opts[:url]
        init_from_url
      elsif opts[:file]
        init_from_file
      elsif opts[:data]
        init_from_data
      end
    end
    
    def url
      @url
    end
    
    def url=(new_url)
      @data = nil
      @url = new_url
    end
    
    def data
      if @data.nil? && !@url.nil?
        res = HTTParty.get @url
        if res.code == 200
          @data = res.body
        else
          raise
        end
      end
      @data
    end
    
    def data=(new_data)
      @url = nil
      @data = new_data
    end
    
    def destroy!
    end
    
    def destroy
      destroy!
    rescue
      false
    end
    
    private
    def init_from_file
    end
    
    def init_from_url
      @url = @attr[:url]
    end
    
    def init_from_data
    end
    
  end
end<commit_msg>Can now initialize an Image from a file or raw data.<commit_after>module CatchNotes
  class Image
    
    attr_accessor :url, :data
    
    def initialize(opts)
      @attr = opts
      @url = nil
      @data = nil
      if opts[:url]
        init_from_url
      elsif opts[:file]
        init_from_file
      elsif opts[:data]
        init_from_data
      end
    end
    
    def url=(new_url)
      @data = nil
      @url = new_url
    end
    
    def data #:nodoc:
      if @data.nil? && !@url.nil?
        res = HTTParty.get @url
        if res.code == 200
          @data = res.body
        else
          raise
        end
      end
      @data
    end
    
    def data=(new_data)
      @url = nil
      @data = new_data
    end
    
    def destroy!
    end
    
    def destroy
      destroy!
    rescue
      false
    end
    
    private
    def init_from_file
      @data = File.read(@attr[:file])
    end
    
    def init_from_url
      @url = @attr[:url]
    end
    
    def init_from_data
      @data = @attr[:data]
    end
    
  end
end
{'fraction_non_alphanumeric': 0.07221115537848606, 'fraction_numerical': 0.00298804780876494, 'mean_word_length': 1.2803632236095346, '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': '1844463', 'n_tokens_mistral': 681, 'n_tokens_neox': 674, 'n_words': 179}