hiroshimarb 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/features/event.feature +5 -0
- data/features/resource/event.yaml +7 -0
- data/features/step_definitions/default_steps.rb +4 -0
- data/hiroshimarb.gemspec +1 -1
- data/lib/hiroshimarb/commands/event.rb +21 -13
- data/lib/hiroshimarb/event.rb +50 -0
- data/lib/hiroshimarb/version.rb +1 -1
- data/resource/event.yaml +10 -0
- data/spec/hiroshimarb/event_spec.rb +20 -0
- metadata +8 -3
data/features/event.feature
CHANGED
@@ -4,6 +4,9 @@
|
|
4
4
|
|
5
5
|
$ hiroshimarb event
|
6
6
|
|
7
|
+
背景:
|
8
|
+
前提 イベントの情報源は"features/resource/event.yaml"
|
9
|
+
|
7
10
|
シナリオ: もっとも近いイベントについての表示
|
8
11
|
もし "hiroshimarb event" を実行
|
9
12
|
ならば 以下の内容を表示:
|
@@ -12,6 +15,7 @@
|
|
12
15
|
|
13
16
|
http://hiroshimarb.github.com/blog/2012/11/16/hiroshimarb-26/
|
14
17
|
|
18
|
+
|
15
19
|
"""
|
16
20
|
シナリオ: イベントについての表示
|
17
21
|
もし "hiroshimarb event all" を実行
|
@@ -25,4 +29,5 @@
|
|
25
29
|
|
26
30
|
http://hiroshimarb.github.com/blog/2012/11/16/hiroshimarb-26/
|
27
31
|
|
32
|
+
|
28
33
|
"""
|
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
- date: '2012-12-01 14:00 - 18:00'
|
3
|
+
title: '広島Ruby勉強会 #026'
|
4
|
+
url: 'http://hiroshimarb.github.com/blog/2012/11/16/hiroshimarb-26/'
|
5
|
+
- date: '2012-11-03 14:00 - 18:00'
|
6
|
+
title: '広島Ruby勉強会 #025'
|
7
|
+
url: 'http://hiroshimarb.github.com/blog/2012/10/15/hiroshimarb-25/'
|
data/hiroshimarb.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'hiroshimarb/member'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.authors = Hiroshimarb::Member.all.map(&:name)
|
8
|
-
gem.email = ["eiel.hal@gmail.com"
|
8
|
+
gem.email = ["eiel.hal@gmail.com"]
|
9
9
|
gem.description = %q{provide `hiroshimarb` command. hiroshimarb is Hiroshima.rb. Hiroshima.rb is local community of Ruby in Hiroshima/Japan}
|
10
10
|
gem.summary = %q{provide `hiroshimarb` command. hiroshimarb is Hiroshima.rb}
|
11
11
|
gem.homepage = "http://github.com/hiroshimarb/hiroshimarb-gem"
|
@@ -1,31 +1,39 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require 'hiroshimarb/event'
|
3
|
+
|
2
4
|
module Hiroshimarb::Commands
|
3
5
|
class Event < Hiroshimarb::Command
|
6
|
+
WDAYS = %w{日 月 火 水 木 金 土}
|
7
|
+
|
4
8
|
def call(*args)
|
5
9
|
sub_command = args.first
|
6
10
|
if sub_command == "all"
|
7
|
-
|
11
|
+
::Hiroshimarb::Event.all.each do |event|
|
12
|
+
puts event_format(event)
|
13
|
+
end
|
8
14
|
else
|
9
|
-
puts recent
|
15
|
+
puts event_format(::Hiroshimarb::Event.recent)
|
10
16
|
end
|
11
17
|
end
|
12
18
|
|
13
|
-
def
|
19
|
+
def event_format(event)
|
14
20
|
<<EOD
|
15
|
-
|
21
|
+
#{time_format(event)} #{event.title}
|
22
|
+
|
23
|
+
#{event.url}
|
16
24
|
|
17
|
-
http://hiroshimarb.github.com/blog/2012/11/16/hiroshimarb-26/
|
18
25
|
EOD
|
19
26
|
end
|
20
27
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
def time_format(event)
|
29
|
+
start = event.start_datetime
|
30
|
+
ent = event.end_datetime
|
31
|
+
wday = WDAYS[start.wday]
|
32
|
+
date = start.strftime("%Y-%m-%d")
|
33
|
+
format = '%H:%M'
|
34
|
+
start_time = start.strftime(format)
|
35
|
+
end_time = ent.strftime(format)
|
36
|
+
"#{date} (#{wday}) #{start_time}-#{end_time}"
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'date'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Hiroshimarb
|
6
|
+
# イベントを表現するクラス
|
7
|
+
class Event
|
8
|
+
attr_accessor :start_datetime, :end_datetime, :url, :title
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def all
|
12
|
+
@events || load_yaml
|
13
|
+
end
|
14
|
+
|
15
|
+
def recent
|
16
|
+
all.last
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource_file_path
|
20
|
+
root = File.join(File.dirname(__FILE__), "..", "..")
|
21
|
+
File.join(root, filename)
|
22
|
+
end
|
23
|
+
|
24
|
+
def filename
|
25
|
+
ENV["resource"] || File.join("resource", "event.yaml")
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_yaml
|
29
|
+
resource_file = resource_file_path
|
30
|
+
events = YAML.parse_file(resource_file).to_ruby.map do |event_hash|
|
31
|
+
event = Event.new
|
32
|
+
event.title = event_hash["title"]
|
33
|
+
event.url = event_hash["url"]
|
34
|
+
event.date_parse event_hash["date"]
|
35
|
+
event
|
36
|
+
end
|
37
|
+
events.sort { |a,b| a.start_datetime <=> b.end_datetime }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# 2012-12-01 14:00 - 18:00 のような形式を処理する
|
42
|
+
def date_parse(datetime_str)
|
43
|
+
start_str, end_str = datetime_str.split(' - ')
|
44
|
+
date_str = start_str.split(' ')[0]
|
45
|
+
end_str = "#{date_str} #{end_str}"
|
46
|
+
self.start_datetime = DateTime.parse(start_str + " JST")
|
47
|
+
self.end_datetime = DateTime.parse(end_str + " JST")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/hiroshimarb/version.rb
CHANGED
data/resource/event.yaml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
---
|
2
|
+
- date: '2013-02-02 14:00 - 18:00'
|
3
|
+
title: '広島Ruby勉強会 #027'
|
4
|
+
url: 'http://hiroshimarb.github.com/blog/2013/01/18/hiroshimarb-27/'
|
5
|
+
- date: '2012-12-01 14:00 - 18:00'
|
6
|
+
title: '広島Ruby勉強会 #026'
|
7
|
+
url: 'http://hiroshimarb.github.com/blog/2012/11/16/hiroshimarb-26/'
|
8
|
+
- date: '2012-11-03 14:00 - 18:00'
|
9
|
+
title: '広島Ruby勉強会 #025'
|
10
|
+
url: 'http://hiroshimarb.github.com/blog/2012/10/15/hiroshimarb-25/'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'hiroshimarb/event'
|
3
|
+
|
4
|
+
module Hiroshimarb
|
5
|
+
describe Event do
|
6
|
+
describe '.all' do
|
7
|
+
subject { Event.all }
|
8
|
+
it { should have(2).items }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.recent' do
|
12
|
+
subject { Event.recent }
|
13
|
+
its(:title) { should eq('広島Ruby勉強会 #026') }
|
14
|
+
it '日付は2012年12月1日' do
|
15
|
+
date = subject.start_datetime
|
16
|
+
expect(date.strftime('%Y-%m-%d')).to eq('2012-12-01')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiroshimarb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -24,7 +24,7 @@ authors:
|
|
24
24
|
autorequire:
|
25
25
|
bindir: bin
|
26
26
|
cert_chain: []
|
27
|
-
date:
|
27
|
+
date: 2013-01-21 00:00:00.000000000 Z
|
28
28
|
dependencies:
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: launchy
|
@@ -78,7 +78,6 @@ description: provide `hiroshimarb` command. hiroshimarb is Hiroshima.rb. Hiroshi
|
|
78
78
|
is local community of Ruby in Hiroshima/Japan
|
79
79
|
email:
|
80
80
|
- eiel.hal@gmail.com
|
81
|
-
- algebraicallyClosedField@gmail.com
|
82
81
|
executables:
|
83
82
|
- hiroshimarb
|
84
83
|
extensions: []
|
@@ -95,6 +94,7 @@ files:
|
|
95
94
|
- features/convert.feature
|
96
95
|
- features/event.feature
|
97
96
|
- features/info.feature
|
97
|
+
- features/resource/event.yaml
|
98
98
|
- features/step_definitions/default_steps.rb
|
99
99
|
- features/support/env.rb
|
100
100
|
- hiroshimarb.gemspec
|
@@ -109,12 +109,15 @@ files:
|
|
109
109
|
- lib/hiroshimarb/commands/member.rb
|
110
110
|
- lib/hiroshimarb/commands/open.rb
|
111
111
|
- lib/hiroshimarb/dsl.rb
|
112
|
+
- lib/hiroshimarb/event.rb
|
112
113
|
- lib/hiroshimarb/information.rb
|
113
114
|
- lib/hiroshimarb/member.rb
|
114
115
|
- lib/hiroshimarb/version.rb
|
116
|
+
- resource/event.yaml
|
115
117
|
- resource/member.rb
|
116
118
|
- spec/hiroshimarb/command_spec.rb
|
117
119
|
- spec/hiroshimarb/dsl_spec.rb
|
120
|
+
- spec/hiroshimarb/event_spec.rb
|
118
121
|
- spec/hiroshimarb/information_spec.rb
|
119
122
|
- spec/hiroshimarb/member_spec.rb
|
120
123
|
- spec/hiroshimarb_spec.rb
|
@@ -147,10 +150,12 @@ test_files:
|
|
147
150
|
- features/convert.feature
|
148
151
|
- features/event.feature
|
149
152
|
- features/info.feature
|
153
|
+
- features/resource/event.yaml
|
150
154
|
- features/step_definitions/default_steps.rb
|
151
155
|
- features/support/env.rb
|
152
156
|
- spec/hiroshimarb/command_spec.rb
|
153
157
|
- spec/hiroshimarb/dsl_spec.rb
|
158
|
+
- spec/hiroshimarb/event_spec.rb
|
154
159
|
- spec/hiroshimarb/information_spec.rb
|
155
160
|
- spec/hiroshimarb/member_spec.rb
|
156
161
|
- spec/hiroshimarb_spec.rb
|