Class: Imas::ProducerSchedule::Client
- Inherits:
-
Object
- Object
- Imas::ProducerSchedule::Client
- Defined in:
- lib/imas/producer_schedule/client.rb
Constant Summary collapse
- REGULAR_ARTICLE =
[ /^デレラジ$/, /^THE IDOLM@STER STATION!!\+$/, /^ラジオdeアイマchu!!$/, /^アイマスタジオ$/, /^【CINDERELLA Night】デレラジA$/, /^CINDERELLA PARTY!$/, /^THE IDOLM@STER STATION!!!$/, /^ミリオンラジオ!$/, /^アイドルマスター シンデレラガールズ .{1,2}話放送$/, /^アイドルマスター シンデレラガールズ .{1,2}話配信(バンダイチャンネル)$/, /^【CINDERELLA Night】アイドルマスター シンデレラガールズ .{1,2}話配信(ニコ生)$/, /^「リスアニ!TV」TVAシンデレラガールズコーナー$/, /^315プロNight!$/, /^アイドルマスター .{1,2}話放送(再放送)$/, /^アイドルマスター シンデレラガールズ .{1,2}話放送(再放送)$/, /^デレラジ☆(スター)$/, ]
- HEADER_OFFSET =
3
- TZID =
'Asia/Tokyo'
- DEFAULT_MONTH_PATH =
File.join(File.('../../../../', __FILE__), 'months.yml')
Instance Method Summary collapse
-
#initialize(month_path = DEFAULT_MONTH_PATH) ⇒ Client
constructor
A new instance of Client.
- #output_cal(output_dir = '.') ⇒ Object
Constructor Details
#initialize(month_path = DEFAULT_MONTH_PATH) ⇒ Client
Returns a new instance of Client.
32 33 34 |
# File 'lib/imas/producer_schedule/client.rb', line 32 def initialize(month_path = DEFAULT_MONTH_PATH) @months = ::YAML.load_file(month_path) end |
Instance Method Details
#output_cal(output_dir = '.') ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/imas/producer_schedule/client.rb', line 36 def output_cal(output_dir = '.') # カレンダー情報定義 cals = [ { name:"プロデューサー予定表", file:"schedule.ics", test: lambda{|schedule| true }, }, { name:"定期配信番組除外版", file:"schedule_irregular.ics", test: lambda{|schedule| REGULAR_ARTICLE.none? {|re| schedule[:article] =~ re} }, }, { name:"定期配信番組のみ", file:"schedule_regular.ics", test: lambda{|schedule| REGULAR_ARTICLE.any? {|re| schedule[:article] =~ re} }, }, { name:"発売日", file:"release_day.ics", test: lambda{|schedule| schedule[:time] == "発売日"} }, { name:"イベント" , file:"event.ics", test: lambda{|schedule| schedule[:genre].include? "イベント"} }, { name:"ニコ生" , file:"nico_live.ics", test: lambda{|schedule| schedule[:genre].include? "ニコ生"} }, ] # タイトル・タイムゾーン設定 cals.each do |cal| calendar = Icalendar::Calendar.new calendar.append_custom_property('X-WR-CALNAME;VALUE=TEXT', cal[:name]) set_timezone calendar cal[:cal] = calendar end @months.each do |year, str, num, type| url = case type when 'a' then "http://idolmaster.jp/schedule/#{year}#{str}.php" when 'b' then "http://idolmaster.jp/schedule/#{year}/#{str}.php" when 'c' then "http://idolmaster.jp/schedule/?ey=#{year}&em=#{str}" end schedules = parse_calendar url month = num # イベント設定 day = nil # いらないかも? schedules.each do |s| e = Icalendar::Event.new # s[:day]がnilならば直前の日付と同じ day = s[:day] || day # 日付時刻 if s[:from].nil? e.dtstart = Icalendar::Values::Date.new(sprintf("%04d%02d%02d", year, month, day), 'tzid' => TZID) else st_tm = to_datetime(year, month, day, *split_time(s[:from])) ed_tm = st_tm unless s[:to].nil? ed_tm = to_datetime(year, month, day, *split_time(s[:to])) end e.dtstart = st_tm e.dtend = ed_tm end # ジャンル e.append_custom_property('X-GENRE;VALUE=TEXT', s[:genre]) # リンク e.append_custom_property('X-LINK;VALUE=TEXT', s[:link]) if s[:link] # 時間 e.append_custom_property('X-TIME;VALUE=TEXT', s[:time]) # サマリ e.summary = s[:article] # 詳細 e.description = s[:description] # カレンダーへ追加 cals.each do |c| c[:cal].add_event e if c[:test].call(s) end end end # カレンダー発行 cals.each do |c| c[:cal].publish open(File.join(output_dir, c[:file]), 'w') { |f| f.write(c[:cal].to_ical) } end end |