Skip to content

Instantly share code, notes, and snippets.

@irasally
Forked from myokoym/5374-sources.rb
Last active August 29, 2015 14:06
Show Gist options
  • Save irasally/5c69b95771e964a4bdbc to your computer and use it in GitHub Desktop.
Save irasally/5c69b95771e964a4bdbc to your computer and use it in GitHub Desktop.
module Gominashi
SOURCES = [
{
name: "toyohira_1",
areas: [
"豊平区 豊平○条○丁目",
"豊平区 旭町○丁目",
"豊平区 水車町○丁目",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["水"],
:paper => [],
:pet => ["木"],
},
special_day: "monday",
},
{
name: "toyohira_2",
areas: [
"豊平区 中の島○条○丁目",
"豊平区 平岸○条○丁目",
"豊平区 美園○条○丁目",
"豊平区 月寒西1条2丁目1番(望月寒川沿いのみ)",
"豊平区 月寒西2条4丁目1番",
"豊平区 月寒中央通1丁目1番(望月寒川沿いのみ)",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["木"],
:paper => [],
:pet => ["月"],
},
special_day: "wednesday",
},
{
name: "toyohira_3",
areas: [
"豊平区 西岡○条○丁目、○番地",
"豊平区 福住○条○丁目",
"豊平区 羊ヶ丘(森林総合研究所公務員宿舎のみ)",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["月"],
:paper => [],
:pet => ["水"],
},
special_day: "thursday",
},
{
name: "toyohira_4",
areas: [
"豊平区 月寒東○条○丁目",
"豊平区 月寒西○条○丁目(月寒西1条2丁目1番の望月寒川沿い・月寒西2条4丁目1番を除く)",
"豊平区 月寒中央通○丁目(月寒中央通1丁目1番の望月寒川沿いを除く)",
"豊平区 羊ヶ丘(北海道農業研修センター宿舎・動物衛生研究所宿舎のみ)",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["金"],
:paper => [],
:pet => ["水"],
},
special_day: "tuesday",
},
{
name: "atsubetsu_1",
areas: [
"厚別区 厚別西○条○丁目、○番地,札幌センター1",
"厚別区 厚別北○条○丁目,札幌センター1",
"厚別区 厚別町山本○番地,札幌センター1",
"厚別区 厚別町小野幌○番地(JR函館本線の北側),札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["火"],
:paper => [],
:pet => ["水"],
},
special_day: "friday",
},
{
name: "atsubetsu_2",
areas: [
"厚別区 厚別西○条○丁目、○番地,札幌センター1",
"厚別区 厚別中央2条~5条の○丁目,札幌センター1",
"厚別区 青葉町11丁目・12丁目、14丁目~16丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["火"],
:paper => [],
:pet => ["金"],
},
special_day: "wednesday",
},
{
name: "atsubetsu_3",
areas: [
"厚別区 厚別南○丁目,札幌センター1",
"厚別区 上野幌○条○丁目,札幌センター1",
"厚別区 厚別町上野幌○番地,札幌センター1",
"厚別区 大谷地西○丁目、東○丁目,札幌センター1",
"厚別区 青葉町1丁目~10丁目、13丁目,札幌センター1",
"厚別区 厚別中央1条5丁目・6丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["金"],
:paper => [],
:pet => ["火"],
},
special_day: "wednesday",
},
{
name: "atsubetsu_4",
areas: [
"厚別区 厚別東○条○丁目,札幌センター1",
"厚別区 厚別町下野幌○番地,札幌センター1",
"厚別区 もみじ台東・西・南・北の○丁目,札幌センター1",
"厚別区 厚別町小野幌○番地(JR函館本線の南側),札幌センター1",
"厚別区 下野幌テクノパーク○丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["水"],
:paper => [],
:pet => ["金"],
},
special_day: "tuesday",
},
{
name: "shiroishi_1",
areas: [
"白石区 中央○条○丁目,札幌センター1",
"白石区 本通1丁目~14丁目(南北),札幌センター1",
"白石区 平和通1丁目~14丁目(南北),札幌センター1",
"白石区 本郷通1丁目~13丁目(南北),札幌センター1",
"白石区 南郷通1丁目~14丁目(南北),札幌センター1",
"白石区 栄通1丁目~14丁目,札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["月"],
:paper => [],
:pet => ["木"],
},
special_day: "wednesday",
},
{
name: "shiroishi_2",
areas: [
"白石区 北郷○条○丁目、○番地,札幌センター1",
"白石区 川北○条○丁目、○番地,札幌センター1",
"白石区 川下○条○丁目、○番地,札幌センター1",
"白石区 菊水元町○条○丁目,札幌センター1",
"白石区 東米里○番地,札幌センター1",
"白石区 米里○条○丁目,札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["木"],
:paper => [],
:pet => ["水"],
},
special_day: "monday",
},
{
name: "shiroishi_3",
areas: [
"白石区 東札幌○条○丁目,札幌センター1",
"白石区 菊水○条○丁目,札幌センター1",
"白石区 菊水上町○条○丁目,札幌センター1",
],
types: {
:burn => ["火", "金"],
:leaf => [],
:not_burn => [],
:plastic => ["水"],
:paper => [],
:pet => ["月"],
},
special_day: "thursday",
},
{
name: "shiroishi_4",
areas: [
"白石区 本通15丁目~21丁目(南北),札幌センター1",
"白石区 平和通15丁目~17丁目(南北),札幌センター1",
"白石区 南郷通15丁目~21丁目(南北),札幌センター1",
"白石区 栄通15丁目~21丁目,札幌センター1",
"白石区 流通センター1丁目~7丁目,札幌センター1",
],
types: {
:burn => ["月", "木"],
:leaf => [],
:not_burn => [],
:plastic => ["金"],
:paper => [],
:pet => ["火"],
},
special_day: "wednesday",
},
]
end
require "date"
require "./5374-sources"
module Gominashi
class Util
class << self
SOURCES.each do |source|
define_method(source[:name]) do |begin_date, end_date, special_order|
days = days(begin_date,
end_date,
source[:types],
source[:special_day],
special_order)
source[:areas].collect do |area|
"#{area},#{days}"
end
end
end
private
def days(begin_date, end_date, types, special_day, special_order)
special_dates = []
current_date = Date.parse(begin_date)
end_date = Date.parse(end_date)
current_special_date = nil
7.times do
if current_date.send("#{special_day}?")
current_special_date = current_date
break
end
current_date += 1
end
raise "ぬるぽ" unless current_special_date
loop do
break unless current_special_date < end_date
special_dates << current_special_date
current_special_date += 7
end
special_dates.reject! do |date|
# TODO: 年末年始は要確認
/\A(1231|010[1-6])\z/ =~ date.strftime("%m%d")
end
special_dates.each_slice(special_order.size) do |dates|
dates.each_with_index do |date, i|
type = special_order[i]
next if type == :leaf and [12, 1, 2, 3, 4].include?(date.month)
types[type] << date.strftime("%Y%m%d")
end
end
types.values.collect {|group|
group.join(" ")
}.join(",")
end
end
end
end
if $0 == __FILE__
special_order = [:paper, :not_burn, :paper, :leaf]
puts Gominashi::Util.toyohira_1("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.toyohira_2("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.toyohira_3("2014-09-01", "2015-10-01", special_order)
puts Gominashi::Util.toyohira_4("2014-09-01", "2015-10-01", special_order)
end
require "test-unit"
require "./5374-util"
class GominashiUtilTest < Test::Unit::TestCase
def test_shiroishi_1
expected = [
"白石区 中央○条○丁目,札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 本通1丁目~14丁目(南北),札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 平和通1丁目~14丁目(南北),札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 本郷通1丁目~13丁目(南北),札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 南郷通1丁目~14丁目(南北),札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
"白石区 栄通1丁目~14丁目,札幌センター1,火 金,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,月,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,木",
]
special_order = [:paper, :not_burn, :paper, :leaf]
assert_equal(expected, Gominashi::Util.shiroishi_1("2014-02-26",
"2014-09-30",
special_order))
end
def test_shiroishi_2
expected = [
"白石区 北郷○条○丁目、○番地,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 川北○条○丁目、○番地,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 川下○条○丁目、○番地,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 菊水元町○条○丁目,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 東米里○番地,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
"白石区 米里○条○丁目,札幌センター1,火 金,20140512 20140609 20140707 20140804 20140901 20140929,20140303 20140331 20140428 20140526 20140623 20140721 20140818 20140915,木,20140224 20140310 20140324 20140407 20140421 20140505 20140519 20140602 20140616 20140630 20140714 20140728 20140811 20140825 20140908 20140922,水",
]
special_order = [:paper, :not_burn, :paper, :leaf]
assert_equal(expected, Gominashi::Util.shiroishi_2("2014-02-24",
"2014-09-30",
special_order))
end
def test_shiroishi_3
expected = [
"白石区 東札幌○条○丁目,札幌センター1,火 金,20140515 20140612 20140710 20140807 20140904,20140306 20140403 20140501 20140529 20140626 20140724 20140821 20140918,水,20140227 20140313 20140327 20140410 20140424 20140508 20140522 20140605 20140619 20140703 20140717 20140731 20140814 20140828 20140911 20140925,月",
"白石区 菊水○条○丁目,札幌センター1,火 金,20140515 20140612 20140710 20140807 20140904,20140306 20140403 20140501 20140529 20140626 20140724 20140821 20140918,水,20140227 20140313 20140327 20140410 20140424 20140508 20140522 20140605 20140619 20140703 20140717 20140731 20140814 20140828 20140911 20140925,月",
"白石区 菊水上町○条○丁目,札幌センター1,火 金,20140515 20140612 20140710 20140807 20140904,20140306 20140403 20140501 20140529 20140626 20140724 20140821 20140918,水,20140227 20140313 20140327 20140410 20140424 20140508 20140522 20140605 20140619 20140703 20140717 20140731 20140814 20140828 20140911 20140925,月",
]
special_order = [:paper, :not_burn, :paper, :leaf]
assert_equal(expected, Gominashi::Util.shiroishi_3("2014-02-27",
"2014-09-30",
special_order))
end
def test_shiroishi_4
expected = [
"白石区 本通15丁目~21丁目(南北),札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
"白石区 平和通15丁目~17丁目(南北),札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
"白石区 南郷通15丁目~21丁目(南北),札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
"白石区 栄通15丁目~21丁目,札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
"白石区 流通センター1丁目~7丁目,札幌センター1,月 木,20140514 20140611 20140709 20140806 20140903,20140305 20140402 20140430 20140528 20140625 20140723 20140820 20140917,金,20140226 20140312 20140326 20140409 20140423 20140507 20140521 20140604 20140618 20140702 20140716 20140730 20140813 20140827 20140910 20140924,火",
]
special_order = [:paper, :not_burn, :paper, :leaf]
assert_equal(expected, Gominashi::Util.shiroishi_4("2014-02-26",
"2014-09-30",
special_order))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment