-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
345 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# vim: fileencoding=utf-8 | ||
|
||
require 'json' | ||
require 'time' | ||
|
||
module RGRB | ||
module Plugin | ||
module OnlineSessionSearch | ||
class Session | ||
# ID | ||
# @return [Integer] | ||
attr_reader :id | ||
# セッション情報の URL | ||
# @return [String] | ||
attr_reader :url | ||
# セッション名 | ||
# @return [String] | ||
attr_reader :name | ||
# ゲームシステム名 | ||
# @return [String] | ||
attr_reader :game_system | ||
# 開始日時 | ||
# @return [Time] | ||
attr_reader :start_time | ||
# 最低人数 | ||
# @return [Integer] | ||
attr_reader :min_members | ||
# 最高人数 | ||
# @return [Integer] | ||
attr_reader :max_members | ||
# アカウント | ||
# @return [String] | ||
attr_reader :account | ||
# ユーザー名 | ||
# @return [String] | ||
attr_reader :user_name | ||
# Twitter 画像 URL | ||
# @return [String] | ||
attr_reader :twitter_image_url | ||
|
||
# JSON からセッション情報へ変換する | ||
# | ||
# 入力される JSON はセッション情報の配列と仮定している | ||
# | ||
# @return [Array<OnlineSessionSearch::Session>] | ||
def self.parse_json(json) | ||
sessions = JSON.parse(json) | ||
sessions.map do |data| | ||
new( | ||
id: data['SID'].to_i, | ||
url: data['url'], | ||
name: data['SesName'], | ||
game_system: data['SysName'], | ||
start_time: Time.parse("#{data['StartTime']} +0900"), | ||
min_members: data['MinMembers'].to_i, | ||
max_members: data['MaxMembers'].to_i, | ||
account: data['account'], | ||
user_name: data['username'], | ||
twitter_image_url: data['twitterimage'] | ||
) | ||
end | ||
end | ||
|
||
def initialize( | ||
id: 0, | ||
url: '', | ||
name: '', | ||
game_system: '', | ||
start_time: Time.now, | ||
min_members: 0, | ||
max_members: 1, | ||
account: '', | ||
user_name: '', | ||
twitter_image_url: '' | ||
) | ||
@id = id | ||
@url = url | ||
@name = name | ||
@game_system = game_system | ||
@start_time = start_time | ||
@min_members = min_members | ||
@max_members = max_members | ||
@account = account | ||
@user_name = user_name | ||
@twitter_image_url = twitter_image_url | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# vim: fileencoding=utf-8 | ||
|
||
require_relative '../../../spec_helper' | ||
require 'rgrb/plugin/online_session_search/generator' | ||
require 'rgrb/plugin/online_session_search/session' | ||
|
||
describe RGRB::Plugin::OnlineSessionSearch::Generator do | ||
let(:generator) { described_class.new } | ||
|
||
shared_examples 'a session' do | ||
let(:session) do | ||
described_class.new( | ||
id: id, | ||
url: url, | ||
name: name, | ||
game_system: game_system, | ||
start_time: start_time, | ||
min_members: min_members, | ||
max_members: max_members, | ||
account: account, | ||
user_name: user_name, | ||
twitter_image_url: twitter_image_url | ||
) | ||
end | ||
end | ||
|
||
describe '#format (private)' do | ||
shared_examples 'a session' do | ||
subject { generator.send(:format, [session]) } | ||
it { should eq([expected_message]) } | ||
end | ||
|
||
context 'セッション情報が見つからなかったとき' do | ||
let(:expected_message) { '開催予定のセッションは見つかりませんでしたの☆' } | ||
|
||
subject { generator.send(:format, []) } | ||
it { should eq([expected_message]) } | ||
end | ||
|
||
context 'セッション 1' do | ||
include_examples 'a session' do | ||
let(:session) do | ||
RGRB::Plugin::OnlineSessionSearch::Session.new( | ||
id: 9999, | ||
url: 'http://session.trpg.net/9999', | ||
name: 'セッション 1', | ||
game_system: 'ソードワールド2.0', | ||
start_time: Time.new(2015, 1, 23, 4, 56, 43, '+09:00'), | ||
min_members: 3, | ||
max_members: 4, | ||
account: '@foo', | ||
user_name: 'Foo', | ||
twitter_image_url: 'http://example.net/foo.png' | ||
) | ||
end | ||
let(:expected_message) do | ||
'ソードワールド2.0 / セッション 1 (2015-01-23 04:56; 3-4人; http://session.trpg.net/9999)' | ||
end | ||
end | ||
end | ||
|
||
context 'セッション 2' do | ||
include_examples 'a session' do | ||
let(:session) do | ||
RGRB::Plugin::OnlineSessionSearch::Session.new( | ||
id: 99999, | ||
url: 'http://session.trpg.net/99999', | ||
name: 'セッション 2', | ||
game_system: 'エリュシオン', | ||
start_time: Time.new(2015, 2, 10, 23, 59, 59, '+09:00'), | ||
min_members: 5, | ||
max_members: 5, | ||
account: '@bar', | ||
user_name: 'Bar', | ||
twitter_image_url: 'http://example.org/bar.png' | ||
) | ||
end | ||
let(:expected_message) do | ||
'エリュシオン / セッション 2 (2015-02-10 23:59; 5人; http://session.trpg.net/99999)' | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.