<commit_before>require "holiday_calendar/version"

require 'date'
require 'tmpdir'
require 'open-uri'
require 'digest'

require 'ri_cal'

module HolidayCalendar
  class HolidayCalendar
    DEFAULT_CAL_URI = 'https://www.google.com/calendar/ical/fi.finnish%23holiday%40group.v.calendar.google.com/public/basic.ics'
    CACHE_MAX_DAYS = 360

    def initialize(opts={})
      @opts = {}
      @holidays = nil
      @cal_uri = opts[:cal_uri] || DEFAULT_CAL_URI

      @calendar_cache = opts[:cache_file] || cache_path
    end

    def cache_path
      File.join(Dir.tmpdir, cache_basename)
    end

    def parse
      if needs_cache_refresh?(@calendar_cache)
        write_cache(@calendar_cache, read_calendar(@cal_uri))
      end

      @holidays = build_hash RiCal.parse(open(@calendar_cache))
    end

    # read calendar from uri. Can be local file or remote path
    def read_calendar(uri)
      File.read('resource/basic.ics')
    end

    def needs_cache_refresh?(fpath)
      !File.exist?(fpath) || cache_age_in_days(fpath) > CACHE_MAX_DAYS
    end

    def cache_age_in_days(fpath)
      (Time.now - File.mtime(fpath)) / 86400
    end

    # return hash keyed by holiday date object, with holiday name as value
    def holidays
      parse unless @holidays
      @holidays
    end

    def weekday?(date)
      !holiday?(date)
    end

    def holiday?(date)
      weekend?(date) || holidays.has_key?(date)
    end

    def weekend?(date)
      [0, 6].include?(date.wday)
    end

    def weekdays_between(d1, d2)
      sign_f = 1
      if d2 < d1<commit_msg>do try to read data from the net<commit_after>require "holiday_calendar/version"

require 'date'
require 'tmpdir'
require 'open-uri'
require 'digest'

require 'ri_cal'

module HolidayCalendar
  class HolidayCalendar
    DEFAULT_CAL_URI = 'https://www.google.com/calendar/ical/fi.finnish%23holiday%40group.v.calendar.google.com/public/basic.ics'
    CACHE_MAX_DAYS = 360

    def initialize(opts={})
      @opts = {}
      @holidays = nil
      @cal_uri = opts[:cal_uri] || DEFAULT_CAL_URI

      @calendar_cache = opts[:cache_file] || cache_path
    end

    def cache_path
      File.join(Dir.tmpdir, cache_basename)
    end

    def parse
      if needs_cache_refresh?(@calendar_cache)
        write_cache(@calendar_cache, read_calendar(@cal_uri))
      end

      @holidays = build_hash RiCal.parse(open(@calendar_cache))
    end

    # read calendar from uri. Can be local file or remote path
    def read_calendar(uri)
      if uri
        open(uri).read
      else
        File.read('resource/basic.ics')
      end
    end

    def needs_cache_refresh?(fpath)
      !File.exist?(fpath) || cache_age_in_days(fpath) > CACHE_MAX_DAYS
    end

    def cache_age_in_days(fpath)
      (Time.now - File.mtime(fpath)) / 86400
    end

    # return hash keyed by holiday date object, with holiday name as value
    def holidays
      parse unless @holidays
      @holidays
    end

    def weekday?(date)
      !holiday?(date)
    end

    def holiday?(date)
      weekend?(date) || holidays.has_key?(date)
    end

    def weekend?(date)
      [0, 6].include?(date.wday)
    end

    def weekdays_between(d1, d2)
      sign_f = 1
      if d2 < d1
{'fraction_non_alphanumeric': 0.10124610591900311, 'fraction_numerical': 0.011838006230529595, 'mean_word_length': 2.81353919239905, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1842239', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1086, 'n_words': 243}