hiroshimarb 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -54,3 +54,9 @@ Hiroshima.rb についての情報を表示します。
54
54
  $ hiroshimarb event
55
55
 
56
56
  Hiroshima.rb の次回のイベントについての情報を表示します。
57
+
58
+ ### aa コマンド
59
+
60
+ $ hiroshimarb aa
61
+
62
+ Hiroshima.rb のアスキーアートを表示します。
@@ -0,0 +1,25 @@
1
+ # language: ja
2
+ 機能: hiroshima.rb のアスキーアートを表示する
3
+ サブコマンド `aa` を使用すると hiroshima.rb のアスキーアートを表示できる
4
+
5
+ $ hiroshimarb aa
6
+
7
+ シナリオ: アスキーアートを表示
8
+ もし "hiroshimarb aa" を実行
9
+ ならば 以下の内容を表示:
10
+ """
11
+ ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
12
+ |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||tf||||||||fl|||
13
+ ||||| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||ll||||||tll||||
14
+ |||| |||||||| ||||| ||||||||||||||||||||||||||||||||||||||||/ |||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||tllt||fllll|||||
15
+ ||| |||||||||| |||| |||||||| ||||||||||||||||||||||||||||||| ||||||| ||||||||||||||||||||||||||||||||||||||||||||| |||||||||tlt||lllltlllll||||||
16
+ || |||||||||||| ||| ||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||| ||||||||| ||||||||||tllllllllllll|||||||
17
+ ||| |||||||||| |||| i || | : ||||| ||||f ||||| . . || | ; || ,||||| |||||||| .||| ||||||flllllllllllllltff|
18
+ |||| |||||||| ||||| ||| | | ||| || ||| || :||||||| l||l | | |||. ||| .|, ||| |||||||| f||| || ||| |||fllllllllllllllltf||
19
+ |||||| |||| ||||||| |||||| | | ||||| | ||||| || .| |||||| | | ||||| ||||| | ||||| |||||||| ||||f | ||||| ||||||||fllllllf|||||||
20
+ ||||||| |||||||| |||||| | | ||||||||. .||| |||||||| || |||||| | | ||||| ||||| |, ||| |||||||| |||||||| ||| |||||||t||tlllllll||||||
21
+ ||||||||| |||||||||| |||||| | | |||||||||| ||||||. |||l |||||| | | |||||. |||||. |||: f ||| ||| |||||||f . ||||||tf|||||tt||ftlt||||
22
+ |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||ft||||||||f||||||||||
23
+ ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
24
+
25
+ """
@@ -4,13 +4,25 @@
4
4
 
5
5
  $ hiroshimarb event
6
6
 
7
- シナリオ: イベントについての表示
7
+ シナリオ: もっとも近いイベントについての表示
8
8
  もし "hiroshimarb event" を実行
9
+ ならば 以下の内容を表示:
10
+ """
11
+ 2012-12-01 (土) 14:00-18:00 広島Ruby勉強会 #026
12
+
13
+ http://hiroshimarb.github.com/blog/2012/11/16/hiroshimarb-26/
14
+
15
+ """
16
+ シナリオ: イベントについての表示
17
+ もし "hiroshimarb event all" を実行
9
18
  ならば 以下の内容を表示:
10
19
  """
11
20
  2012-11-03 (土) 14:00-18:00 広島Ruby勉強会 #025
12
21
 
13
22
  http://hiroshimarb.github.com/blog/2012/10/15/hiroshimarb-25/
14
23
 
24
+ 2012-12-01 (土) 14:00-18:00 広島Ruby勉強会 #026
25
+
26
+ http://hiroshimarb.github.com/blog/2012/11/16/hiroshimarb-26/
15
27
 
16
28
  """
@@ -0,0 +1,34 @@
1
+ module Hiroshimarb
2
+
3
+ # コマンドを実装する際の基底クラス
4
+ class Command
5
+
6
+ class << self
7
+
8
+ def commands
9
+ @commands ||= {}
10
+ end
11
+
12
+ def inherited(subclass)
13
+ name = subclass.command_name
14
+ commands[name] = subclass
15
+ end
16
+
17
+ def find(command_name)
18
+ if command = commands[command_name.to_sym]
19
+ command.new
20
+ else
21
+ nil
22
+ end
23
+ end
24
+
25
+ def command_name
26
+ name.split('::').last.downcase.to_sym
27
+ end
28
+ end
29
+
30
+ def call(arg)
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'hiroshimarb/command'
3
+
4
+ module Hiroshimarb::Commands
5
+ class Aa < Hiroshimarb::Command
6
+ def call(*args)
7
+ puts <<EOD
8
+ ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
9
+ |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||tf||||||||fl|||
10
+ ||||| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||ll||||||tll||||
11
+ |||| |||||||| ||||| ||||||||||||||||||||||||||||||||||||||||/ |||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||tllt||fllll|||||
12
+ ||| |||||||||| |||| |||||||| ||||||||||||||||||||||||||||||| ||||||| ||||||||||||||||||||||||||||||||||||||||||||| |||||||||tlt||lllltlllll||||||
13
+ || |||||||||||| ||| ||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||| ||||||||| ||||||||||tllllllllllll|||||||
14
+ ||| |||||||||| |||| i || | : ||||| ||||f ||||| . . || | ; || ,||||| |||||||| .||| ||||||flllllllllllllltff|
15
+ |||| |||||||| ||||| ||| | | ||| || ||| || :||||||| l||l | | |||. ||| .|, ||| |||||||| f||| || ||| |||fllllllllllllllltf||
16
+ |||||| |||| ||||||| |||||| | | ||||| | ||||| || .| |||||| | | ||||| ||||| | ||||| |||||||| ||||f | ||||| ||||||||fllllllf|||||||
17
+ ||||||| |||||||| |||||| | | ||||||||. .||| |||||||| || |||||| | | ||||| ||||| |, ||| |||||||| |||||||| ||| |||||||t||tlllllll||||||
18
+ ||||||||| |||||||||| |||||| | | |||||||||| ||||||. |||l |||||| | | |||||. |||||. |||: f ||| ||| |||||||f . ||||||tf|||||tt||ftlt||||
19
+ |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||ft||||||||f||||||||||
20
+ ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
21
+ EOD
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hiroshimarb::Commands
3
+ class Event < Hiroshimarb::Command
4
+ def call(*args)
5
+ sub_command = args.first
6
+ if sub_command == "all"
7
+ puts all
8
+ else
9
+ puts recent
10
+ end
11
+ end
12
+
13
+ def recent
14
+ <<EOD
15
+ 2012-12-01 (土) 14:00-18:00 広島Ruby勉強会 #026
16
+
17
+ http://hiroshimarb.github.com/blog/2012/11/16/hiroshimarb-26/
18
+ EOD
19
+ end
20
+
21
+ def all
22
+ rest = <<EOD
23
+ 2012-11-03 (土) 14:00-18:00 広島Ruby勉強会 #025
24
+
25
+ http://hiroshimarb.github.com/blog/2012/10/15/hiroshimarb-25/
26
+
27
+ EOD
28
+ rest + recent
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'hiroshimarb/command'
3
+
4
+ module Hiroshimarb::Commands
5
+ class Help < Hiroshimarb::Command
6
+ def call(*args)
7
+ puts <<EOD
8
+ Usage: hiroshimarb command
9
+ Available commands:
10
+ open : open the website relevant to Hiroshima in a web browser
11
+ : subcommands
12
+ : hiroshimarb - Hiroshim.rb [default]
13
+ : ipad - 広島弁吹替シリーズ
14
+ : oc-h - おしい広島県
15
+ : city - 広島市
16
+ : pref - 広島県
17
+ info : disploy information of Hiroshimar.rb
18
+ member : display the member of Hiroshima.rb
19
+ event : display next event of Hiroshima.rb
20
+ aa : display ascii art of Hiroshima.rb
21
+ EOD
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'hiroshimarb/information'
2
+
3
+ module Hiroshimarb::Commands
4
+ class Info < Hiroshimarb::Command
5
+ def call(*args)
6
+ puts Hiroshimarb::Information.information
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'hiroshimarb/member'
2
+
3
+ module Hiroshimarb::Commands
4
+ class Member < Hiroshimarb::Command
5
+ def call(*args)
6
+ Hiroshimarb::Member.all.reduce(nil) do |acc, member|
7
+ puts acc if acc
8
+ puts member.to_s
9
+ acc = '-'*80
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'launchy'
4
+ require 'uri'
5
+ require 'hiroshimarb/command'
6
+
7
+ module Hiroshimarb::Commands
8
+ class Open < Hiroshimarb::Command
9
+
10
+ @@default_key = 'hiroshimarb'
11
+
12
+ def call(*args)
13
+ command = args.first
14
+ command ||= @@default_key
15
+ Launchy.open key2url(command)
16
+ end
17
+
18
+ def key2url(key)
19
+ case key
20
+ when 'hiroshimarb'
21
+ 'http://hiroshimarb.github.com'
22
+ when 'oc-h'
23
+ 'http://oc-h.jp'
24
+ when 'ipad'
25
+ URI.encode 'http://kita.dyndns.org/wiki/?広島弁吹き替えシリーズ'
26
+ when 'city'
27
+ 'http://www.city.hiroshima.lg.jp'
28
+ when 'pref'
29
+ 'http://www.pref.hiroshima.lg.jp'
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module Hiroshimarb::Commands
2
+ def self.load_commands
3
+ commands_dir = File.join(File.dirname(__FILE__), "commands")
4
+ path = File.join(commands_dir, "*.rb")
5
+ Dir.glob(path).each do |file|
6
+ require file
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Hiroshimarb
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/hiroshimarb.rb CHANGED
@@ -1,29 +1,24 @@
1
1
  require "hiroshimarb/version"
2
- require 'hiroshimarb/cli'
3
2
 
4
3
  module Hiroshimarb
5
- extend CLI
6
-
7
- autoload(:Information, "hiroshimarb/information")
8
- autoload(:Open, "hiroshimarb/open")
4
+ autoload(:Command, "hiroshimarb/command")
5
+ autoload(:Commands, "hiroshimarb/commands")
9
6
 
10
7
  class << self
11
8
  def execute(argv)
9
+ Commands.load_commands
12
10
  return help if argv.count == 0
13
11
 
14
- command = argv.shift
15
- case command
16
- when 'open'
17
- open *argv
18
- when 'info'
19
- info
20
- when 'member'
21
- member
22
- when 'event'
23
- event
12
+ first = argv.shift
13
+ if command = Command.find(first)
14
+ command.call *argv
24
15
  else
25
16
  help
26
17
  end
27
18
  end
19
+
20
+ def help(*argv)
21
+ Commands::Help.new.call *argv
22
+ end
28
23
  end
29
24
  end
@@ -0,0 +1,15 @@
1
+ require 'hiroshimarb/command'
2
+
3
+ class Sample < Hiroshimarb::Command
4
+ end
5
+
6
+ module Hiroshimarb
7
+ describe Command do
8
+ describe '.find' do
9
+ subject { Command.find command }
10
+ let(:command) { 'sample' }
11
+ it { should be_kind_of(Command) }
12
+ it { should be_kind_of(Sample) }
13
+ end
14
+ end
15
+ end
@@ -1,48 +1,17 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'hiroshimarb'
3
+ require 'launchy'
3
4
 
4
5
  describe Hiroshimarb do
5
6
  describe '.execute' do
6
7
  subject { Hiroshimarb.execute argv }
7
- context "when 第1引数が 'open'" do
8
- let(:argv) { ['open', 'hiroshimarb'] }
9
8
 
10
- it "open メソッドが呼ばれる" do
11
- Hiroshimarb.should_receive(:open).with('hiroshimarb')
12
- subject
13
- end
14
- end
15
-
16
- context "when 第1引数が 'info'" do
17
- let(:argv) { ['info'] }
18
-
19
- it "info メソッドが呼ばれる" do
20
- Hiroshimarb.should_receive(:info)
21
- subject
22
- end
23
- end
24
-
25
- context "when 第1引数が 'member'" do
26
- let(:argv) { ['member'] }
9
+ let(:argv) { %w{open} }
27
10
 
28
- it "member メソッドが呼ばれる" do
29
- Hiroshimarb.should_receive(:member)
30
- subject
31
- end
11
+ before :each do
12
+ Hiroshimarb::Command.should_receive(:find) { proc { "open!!" } }
32
13
  end
33
14
 
34
- context "when 引数がない場合'" do
35
- let(:argv) { [] }
36
-
37
- it "help メソッドが呼ばれる" do
38
- Hiroshimarb.should_receive(:help)
39
- subject
40
- end
41
- end
42
- end
43
-
44
- describe "Infomation" do
45
- subject { Hiroshimarb::Information }
46
- its(:class) { should eq(Class) }
15
+ it { should eq("open!!") }
47
16
  end
48
17
  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.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -23,7 +23,7 @@ authors:
23
23
  autorequire:
24
24
  bindir: bin
25
25
  cert_chain: []
26
- date: 2012-10-30 00:00:00.000000000 Z
26
+ date: 2012-11-26 00:00:00.000000000 Z
27
27
  dependencies:
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: launchy
@@ -89,20 +89,27 @@ files:
89
89
  - README.md
90
90
  - Rakefile
91
91
  - bin/hiroshimarb
92
+ - features/aa.feature
92
93
  - features/event.feature
93
94
  - features/info.feature
94
95
  - features/step_definitions/default_steps.rb
95
96
  - features/support/env.rb
96
97
  - hiroshimarb.gemspec
97
98
  - lib/hiroshimarb.rb
98
- - lib/hiroshimarb/cli.rb
99
+ - lib/hiroshimarb/command.rb
100
+ - lib/hiroshimarb/commands.rb
101
+ - lib/hiroshimarb/commands/aa.rb
102
+ - lib/hiroshimarb/commands/event.rb
103
+ - lib/hiroshimarb/commands/help.rb
104
+ - lib/hiroshimarb/commands/info.rb
105
+ - lib/hiroshimarb/commands/member.rb
106
+ - lib/hiroshimarb/commands/open.rb
99
107
  - lib/hiroshimarb/dsl.rb
100
108
  - lib/hiroshimarb/information.rb
101
109
  - lib/hiroshimarb/member.rb
102
- - lib/hiroshimarb/open.rb
103
110
  - lib/hiroshimarb/version.rb
104
111
  - resource/member.rb
105
- - spec/hiroshimarb/cli_spec.rb
112
+ - spec/hiroshimarb/command_spec.rb
106
113
  - spec/hiroshimarb/dsl_spec.rb
107
114
  - spec/hiroshimarb/information_spec.rb
108
115
  - spec/hiroshimarb/member_spec.rb
@@ -132,11 +139,12 @@ signing_key:
132
139
  specification_version: 3
133
140
  summary: provide `hiroshimarb` command. hiroshimarb is Hiroshima.rb
134
141
  test_files:
142
+ - features/aa.feature
135
143
  - features/event.feature
136
144
  - features/info.feature
137
145
  - features/step_definitions/default_steps.rb
138
146
  - features/support/env.rb
139
- - spec/hiroshimarb/cli_spec.rb
147
+ - spec/hiroshimarb/command_spec.rb
140
148
  - spec/hiroshimarb/dsl_spec.rb
141
149
  - spec/hiroshimarb/information_spec.rb
142
150
  - spec/hiroshimarb/member_spec.rb
@@ -1,56 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'hiroshimarb/member'
3
- require 'rubygems'
4
- require 'launchy'
5
- require 'uri'
6
-
7
- module Hiroshimarb
8
- # コマンドラインから呼びだされる場合のサブコマンドを実装する
9
- module CLI
10
- # Hiroshim.rbのウェブサイトをブラウザで開く
11
- def open(key = nil)
12
- Open.open(key)
13
- end
14
-
15
- # Hiroshim.rbの情報を標準出力へ表示
16
- def info
17
- puts Information.information
18
- end
19
-
20
- # Hiroshima.rbのメンバーを標準出力へ表示
21
- def member
22
- Member.all.reduce(nil) do |acc, member|
23
- puts acc if acc
24
- puts member.to_s
25
- acc = '-'*80
26
- end
27
- end
28
-
29
- # Hiroshima.rbのイベントを標準出力へ表示
30
- def event
31
- puts <<EOD
32
- 2012-11-03 (土) 14:00-18:00 広島Ruby勉強会 #025
33
-
34
- http://hiroshimarb.github.com/blog/2012/10/15/hiroshimarb-25/
35
-
36
- EOD
37
- end
38
-
39
- def help
40
- puts <<EOD
41
- Usage: hiroshimarb command
42
- Available commands:
43
- open : open the website relevant to Hiroshima in a web browser
44
- : subcommands
45
- : hiroshimarb - Hiroshim.rb [default]
46
- : ipad - 広島弁吹替シリーズ
47
- : oc-h - おしい広島県
48
- : city - 広島市
49
- : pref - 広島県
50
- info : disploy information of Hiroshimar.rb
51
- member : display the member of Hiroshima.rb
52
- event : display next event of Hiroshima.rb
53
- EOD
54
- end
55
- end
56
- end
@@ -1,26 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'rubygems'
3
- require 'launchy'
4
-
5
- module Hiroshimarb
6
- class Open
7
- class << self
8
- def open(key = nil)
9
- key ||= 'hiroshimarb'
10
- url = case key
11
- when 'hiroshimarb'
12
- 'http://hiroshimarb.github.com'
13
- when 'oc-h'
14
- 'http://oc-h.jp'
15
- when 'ipad'
16
- URI.encode 'http://kita.dyndns.org/wiki/?広島弁吹き替えシリーズ'
17
- when 'city'
18
- 'http://www.city.hiroshima.lg.jp'
19
- when 'pref'
20
- 'http://www.pref.hiroshima.lg.jp'
21
- end
22
- Launchy.open url
23
- end
24
- end
25
- end
26
- end
@@ -1,91 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'hiroshimarb/cli'
3
-
4
- describe Hiroshimarb::CLI do
5
- let(:cli) do
6
- Object.new.extend Hiroshimarb::CLI
7
- end
8
-
9
- let(:stdout) do
10
- $stdout.seek 0
11
- $stdout.read
12
- end
13
-
14
- before :each do
15
- $stdout = StringIO.new
16
- end
17
-
18
- describe '#open' do
19
- subject { cli.open(arg) }
20
-
21
- context '引数なし' do
22
- let(:arg) { nil }
23
- it "Hiroshima.rbのウェブサイトを表示" do
24
- Launchy.should_receive(:open).with('http://hiroshimarb.github.com')
25
- subject
26
- end
27
- end
28
-
29
- context '引数 "oc-h"' do
30
- let(:arg) { "oc-h" }
31
- it "おしい広島県のウェブサイトを表示" do
32
- Launchy.should_receive(:open).with('http://oc-h.jp')
33
- subject
34
- end
35
- end
36
-
37
- context '引数 "ipad"' do
38
- let(:arg) { "ipad" }
39
- it "広島弁吹替シリーズのサイトを表示" do
40
- Launchy.should_receive(:open).with('http://kita.dyndns.org/wiki/?%E5%BA%83%E5%B3%B6%E5%BC%81%E5%90%B9%E3%81%8D%E6%9B%BF%E3%81%88%E3%82%B7%E3%83%AA%E3%83%BC%E3%82%BA')
41
- subject
42
- end
43
- end
44
-
45
- context '引数 "city"' do
46
- let(:arg) { 'city' }
47
- it '広島市のサイトを表示' do
48
- Launchy.should_receive(:open).with('http://www.city.hiroshima.lg.jp')
49
- subject
50
- end
51
- end
52
-
53
- context '引数 "pref"' do
54
- let(:arg) { 'pref' }
55
- it '広島市のサイトを表示' do
56
- Launchy.should_receive(:open).with('http://www.pref.hiroshima.lg.jp')
57
- subject
58
- end
59
- end
60
- end
61
-
62
- describe '#info' do
63
- subject { cli.info }
64
- it "Hiroshima.rbについて出力される" do
65
- subject
66
- expect(stdout).to match("Hiroshima.rbについて")
67
- end
68
-
69
- it "イベントについて出力される" do
70
- subject
71
- expect(stdout).to match("勉強会やもくもくする会")
72
- end
73
- end
74
-
75
- describe '#member' do
76
- subject { cli.member }
77
- it 'Hiroshim.rbのメンバーを出力' do
78
- Hiroshimarb::Member.stub(:all) { %W{hoge mogu} }
79
- subject
80
- expect(stdout).to eq("hoge\n" + '-'*80 + "\nmogu\n")
81
- end
82
- end
83
-
84
- describe '#help' do
85
- subject { cli.help }
86
- it '使い方を出力' do
87
- subject
88
- expect(stdout).to match("Usage")
89
- end
90
- end
91
- end