<commit_before>#!/usr/bin/env ruby

require 'date'
require './lib/rate.rb'
require 'ostruct'

class Movie

  WEIGHT = 0

  include Rate
  attr_accessor :list, :link, :name, :year, :country, :date, :genre, :duration, :rating, :director, :actors, :my_rating, :view_date

  @@filters = {}

  class << self
    attr_accessor :filters
  end

  def initialize(list=nil, attributes)
    @list       = list
    @link       = attributes[:link]
    @name       = attributes[:name]
    @year       = attributes[:year].to_i
    @country    = attributes[:country]
    @date       = parse_date(attributes[:date])
    @genre      = attributes[:genre]
    @duration   = attributes[:duration].to_i
    @rating     = attributes[:rating].to_f.round(1)
    @director   = attributes[:director]
    @actors     = attributes[:actors]
    @my_rating  = 0
    @view_date  = nil
  end

  def method_missing(method_sym, *arguments, &block)
    method = method_sym.to_s.chomp("?").capitalize
    if method_sym.to_s.match(/\w+\?$/)
      has_genre?(method)
    else
      super
    end
  end

  def self.create(list, args)
    @movie  = OpenStruct.new(year: args[:year].to_i)
    cls     = @@filters.detect { |cls, filter| @movie.instance_eval(&filter) }.first
    cls.new(list, args)
  end

  def self.filter(&block)
    @@filters.store(self, block)
  end

  def self.print_format(format_str)
    define_method(:description) do
      format_str % self.to_h
    end
  end

  def self.weight(arg)
    const_set("WEIGHT", arg)
  end

  class AncientMovie < Movie
    filter { (1900..1944).cover?(year) }
    print_format "%{name} — so old movie (%{year} year)"
    weight 0.3
  end

  class ClassicMovie < Movie
    filter { (1945..1967).cover?(year) }
    print_format "%{name} — the classic movie. The director is %{director}. Maybe you wanna see his other movies? \n%{dir_movie}"
    weight 0.5
  end

  class ModernMovie < Movie
    filter { (1968..1999).cover?(year) }
    print_format "%{name} — modern movie. Starring: %{actors}"
    weight 0.7
  end

  class NewMovie < Movie
    filter { (2000..Date.today.year).cover?(year) }
    print_format "%{name} — novelty!"
    weight 1.0
  end

  # Parse the date
  def parse_date(date)
    fmt = case date.length
    when 0..4
      '%Y'
    when 5..7
      '%Y-%m'
    else
      '%Y-%m-%d'
    end
    Date.strptime(date, fmt)
  end

  # Check the movie for viewing
  def viewed?
    !@view_date.nil?
  end

  def has_genre?(genre)
    @genre.include?(genre)
  end

  # Check that movies has genre
  def has_genres?(*genres)
    (@genre - genres).empty?
  end

  # Human readable output
  def inspect
    "\n#{self.class}, name: #{@name}, year: #{@year}, rating: #{@rating}, my_rating: #{@my_rating}, country: #{@country}, date: #{@date}, genre: #{@genre}, duration: #{@duration}, director: #{@director}, actors: #{@actors}, view_date: #{@view_date}"
  end

  def to_h
    {
      dir_movie:  @list.by_director(@director),
      list:       @list,
      name:       @name,
      year:       @year,
      rating:     @rating,
      my_rating:  @my_rating,
      country:    @country,
      date:       @date,
      genre:      @genre,
      duration:   @duration,
      director:   @director,
      actors:     @actors,
      view_date:  @view_date
    }
  end

end
<commit_msg>Added getter for @@filters<commit_after>#!/usr/bin/env ruby

require 'date'
require './lib/rate.rb'
require 'ostruct'

class Movie

  WEIGHT = 0

  include Rate
  attr_accessor :list, :link, :name, :year, :country, :date, :genre, :duration, :rating, :director, :actors, :my_rating, :view_date

  @@filters = {}

  def initialize(list=nil, attributes)
    @list       = list
    @link       = attributes[:link]
    @name       = attributes[:name]
    @year       = attributes[:year].to_i
    @country    = attributes[:country]
    @date       = parse_date(attributes[:date])
    @genre      = attributes[:genre]
    @duration   = attributes[:duration].to_i
    @rating     = attributes[:rating].to_f.round(1)
    @director   = attributes[:director]
    @actors     = attributes[:actors]
    @my_rating  = 0
    @view_date  = nil
  end

  def method_missing(method_sym, *arguments, &block)
    method = method_sym.to_s.chomp("?").capitalize
    if method_sym.to_s.match(/\w+\?$/)
      has_genre?(method)
    else
      super
    end
  end

  def self.create(list, args)
    @movie  = OpenStruct.new(year: args[:year].to_i)
    cls     = @@filters.detect { |cls, filter| @movie.instance_eval(&filter) }.first
    cls.new(list, args)
  end

  def self.filter(&block)
    @@filters.store(self, block)
  end

  def self.print_format(format_str)
    define_method(:description) do
      format_str % self.to_h
    end
  end

  def self.weight(arg)
    const_set("WEIGHT", arg)
  end

  def self.filters
    @@filters
  end

  class AncientMovie < Movie
    filter { (1900..1944).cover?(year) }
    print_format "%{name} — so old movie (%{year} year)"
    weight 0.3
  end

  class ClassicMovie < Movie
    filter { (1945..1967).cover?(year) }
    print_format "%{name} — the classic movie. The director is %{director}. Maybe you wanna see his other movies? \n%{dir_movie}"
    weight 0.5
  end

  class ModernMovie < Movie
    filter { (1968..1999).cover?(year) }
    print_format "%{name} — modern movie. Starring: %{actors}"
    weight 0.7
  end

  class NewMovie < Movie
    filter { (2000..Date.today.year).cover?(year) }
    print_format "%{name} — novelty!"
    weight 1.0
  end

  # Parse the date
  def parse_date(date)
    fmt = case date.length
    when 0..4
      '%Y'
    when 5..7
      '%Y-%m'
    else
      '%Y-%m-%d'
    end
    Date.strptime(date, fmt)
  end

  # Check the movie for viewing
  def viewed?
    !@view_date.nil?
  end

  def has_genre?(genre)
    @genre.include?(genre)
  end

  # Check that movies has genre
  def has_genres?(*genres)
    (@genre - genres).empty?
  end

  # Human readable output
  def inspect
    "\n#{self.class}, name: #{@name}, year: #{@year}, rating: #{@rating}, my_rating: #{@my_rating}, country: #{@country}, date: #{@date}, genre: #{@genre}, duration: #{@duration}, director: #{@director}, actors: #{@actors}, view_date: #{@view_date}"
  end

  def to_h
    {
      dir_movie:  @list.by_director(@director),
      list:       @list,
      name:       @name,
      year:       @year,
      rating:     @rating,
      my_rating:  @my_rating,
      country:    @country,
      date:       @date,
      genre:      @genre,
      duration:   @duration,
      director:   @director,
      actors:     @actors,
      view_date:  @view_date
    }
  end

end

{'fraction_non_alphanumeric': 0.14387399666818113, 'fraction_numerical': 0.01302438285627745, 'mean_word_length': 2.6067722555980337, 'pattern_counts': {'":': 0, '<': 13, '<?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': '2166167', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2268, 'n_words': 566}