#!/usr/local/bin/ruby require 'pp' class AnondArchive attr_reader :url, :year, :month, :year_urls, :year_month_urls, :year_month_urls_from_200609_to_201708 def initialize(url="https://anond.hatelabo.jp/archive/")#, year, month) @url = url;# @year = year; @month = month end def add_year @year_urls = [] (6..17).each do |n| n = "0" + n.to_s unless n.to_s =~ %r|^[1][0-7]$| @year = "20" + n.to_s @year_urls << @url + @year end return @year_urls end def add_month @year_month_urls = [] @year_urls.each do |year_url| (1..12).each do |n| # n = "0" + n.to_s unless n =~ %r|^[0-9][0-2]$| #integerオブジェクトは正規表現マッチできなかったから注意 n = "0" + n.to_s unless n.to_s =~ %r|^[0-9][0-2]$| @year_month_urls << year_url + n.to_s end end return @year_month_urls end def make_year_month_urls_from_200609_to_201708 @year_month_urls_from_200609_to_201708 = [] @year_month_urls.each do |year_month_url| case year_month_url when "https://anond.hatelabo.jp/archive/200601" when "https://anond.hatelabo.jp/archive/200602" when "https://anond.hatelabo.jp/archive/200603" when "https://anond.hatelabo.jp/archive/200604" when "https://anond.hatelabo.jp/archive/200605" when "https://anond.hatelabo.jp/archive/200606" when "https://anond.hatelabo.jp/archive/200607" when "https://anond.hatelabo.jp/archive/200608" when "https://anond.hatelabo.jp/archive/201709" when "https://anond.hatelabo.jp/archive/201710" when "https://anond.hatelabo.jp/archive/201711" when "https://anond.hatelabo.jp/archive/201712" else @year_month_urls_from_200609_to_201708 << year_month_url end end return @year_month_urls_from_200609_to_201708 end end sample = AnondArchive.new("https://anond.hatelabo.jp/archive/") #puts sample.url #puts sample.year #puts sample.month sample.add_year sample.add_month pp sample.make_year_month_urls_from_200609_to_201708