<commit_before>require "feedzirra"
require "rss-feed/railtie" if defined?(Rails)

module Rss
  module Feed

    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      def feed_entries
        @feed ? @feed.entries : []
      end

      def subscribes_to(feed_url)
        @feed_url = feed_url
      end

      def feed_url
        @feed_url
      end

      def get_feed
        Feedzirra::Feed.fetch_and_parse(@feed_url).tap do |feed|
          @feed = feed != 0 ? feed : []
        end
      end

      def update_from_feed
        get_feed
        feed_entries.each do |entry|
          entry.sanitize!
          entry_attributes = entry.as_json.inject({}) do |mem, (key, value)|
            mem[key.to_sym] = value; mem
          end
          self.find_or_create_by entry_attributes
        end
      end
    end
  end<commit_msg>.get_feed returns nil if the feed can't be loaded.<commit_after>require "feedzirra"
require "rss-feed/railtie" if defined?(Rails)

module Rss
  module Feed

    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      def feed_entries
        @feed ? @feed.entries : []
      end

      def subscribes_to(feed_url)
        @feed_url = feed_url
      end

      def feed_url
        @feed_url
      end

      def get_feed
        Feedzirra::Feed.fetch_and_parse(@feed_url).tap do |feed|
          @feed = feed != 0 ? feed : nil
        end
      end

      def update_from_feed
        get_feed
        feed_entries.each do |entry|
          entry.sanitize!
          entry_attributes = entry.as_json.inject({}) do |mem, (key, value)|
            mem[key.to_sym] = value; mem
          end
          self.find_or_create_by entry_attributes
        end
      end
    end
  end
{'fraction_non_alphanumeric': 0.07997762863534676, 'fraction_numerical': 0.0011185682326621924, 'mean_word_length': 1.8715890850722312, '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': '1149417', 'n_tokens_mistral': 583, 'n_tokens_neox': 561, 'n_words': 136}