Sha256: 770da459c672ff511644c98c667fb18c320854699dc0c9689f798005f891c052
Contents?: true
Size: 1009 Bytes
Versions: 7
Compression:
Stored size: 1009 Bytes
Contents
# frozen_string_literal: true module QiitaTrend class Target attr_reader :type, :url, :need_login, :cache def initialize(trend_type = TrendType::DAILY, date = nil) @type = trend_type @url = trend_url(trend_type) @need_login = trend_type != TrendType::DAILY @cache = cache_name(trend_type, date) end private def trend_url(type) case type when TrendType::DAILY then 'https://qiita.com/' when TrendType::WEEKLY then 'https://qiita.com/?scope=weekly' when TrendType::MONTHLY then 'https://qiita.com/?scope=monthly' end end def cache_name(type, date) return "#{date}_#{type}.html" unless date.nil? if Time.now.hour >= 5 && Time.now.hour < 17 "#{Date.today.strftime('%Y%m%d')}05_#{type}.html" elsif Time.now.hour >= 17 "#{Date.today.strftime('%Y%m%d')}17_#{type}.html" elsif Time.now.hour < 5 "#{(Date.today - 1).strftime('%Y%m%d')}17_#{type}.html" end end end end
Version data entries
7 entries across 7 versions & 1 rubygems