Created
October 30, 2016 00:38
-
-
Save jacoyutorius/ebbd4df060c8f49685854f925ecdf68b to your computer and use it in GitHub Desktop.
文字列に含まれる日付からDateオブジェクトを取り出す
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "rspec" | |
| require "pry" | |
| class HamamatsuEventCalendar | |
| def parse text | |
| ret = text.match(/(?<year>(\d*))年(?<month>(\d*))月(?<day>(\d*))日/) | |
| Date.new(ret[:year].to_i, ret[:month].to_i, ret[:day].to_i) | |
| rescue | |
| nil | |
| end | |
| end | |
| # データはここから | |
| # http://www.city.hamamatsu.shizuoka.jp/cgi-bin/event_cal/cal_month.cgi | |
| describe HamamatsuEventCalendar do | |
| let(:parser){ HamamatsuEventCalendar.new } | |
| describe "#parse" do | |
| it "若木信吾監督作品特別上映2016年10月1日(土曜日)" do | |
| text = "若木信吾監督作品特別上映2016年10月1日(土曜日)" | |
| expect(parser.parse(text).to_s).to eq "2016-10-01" | |
| end | |
| it "「世界音楽の祭典in浜松2016」アクトシティ浜松市民ロビー写真展 2016年9月8日(木曜日)~2016年11月6日(日曜日)" do | |
| text = "「世界音楽の祭典in浜松2016」アクトシティ浜松市民ロビー写真展 2016年9月8日(木曜日)~2016年11月6日(日曜日)" | |
| expect(parser.parse(text).to_s).to eq "2016-09-08" | |
| end | |
| it "つなげよう先人の知恵『食編・おみそづくりに挑戦』2016年" do | |
| text = "つなげよう先人の知恵『食編・おみそづくりに挑戦』2016年" | |
| expect(parser.parse(text)).to be_nil | |
| end | |
| it "つなげよう先人の知恵『食編・おみそづくりに挑戦』2016年10月" do | |
| text = "つなげよう先人の知恵『食編・おみそづくりに挑戦』2016年" | |
| expect(parser.parse(text)).to be_nil | |
| end | |
| it "つなげよう先人の知恵『食編・おみそづくりに挑戦』1日2日3日" do | |
| text = "つなげよう先人の知恵『食編・おみそづくりに挑戦』2016年" | |
| expect(parser.parse(text)).to be_nil | |
| end | |
| it "若木信吾監督作品特別上映2" do | |
| text = "若木信吾監督作品特別上映2" | |
| expect(parser.parse(text)).to be_nil | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment