cub 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/cub.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/cub/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["kano4"]
6
+ gem.email = ["shinji.warp@gmail.com"]
7
+ gem.description = %q{Cub fetches stock information.}
8
+ gem.summary = %q{Fetch stock information}
9
+ gem.homepage = "https://github.com/kano4/cub"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "cub"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Cub::VERSION
17
+
18
+ gem.add_development_dependency "rspec"
19
+ end
data/lib/cub.rb ADDED
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/cub/version')
3
+ require 'yaml'
4
+
5
+ module Cub
6
+ @@companies = YAML.load_file(File.dirname(__FILE__) + '/../companies.yml')
7
+
8
+ class CompanyException < StandardError
9
+ end
10
+
11
+ def self.company(code)
12
+ if valid_code?(code)
13
+ company_name(code)
14
+ else
15
+ raise CompanyException, "無効な証券コード"
16
+ end
17
+ end
18
+
19
+ private
20
+ def self.valid_code?(code)
21
+ /^\d{4}$/ =~ code.to_s
22
+ end
23
+
24
+ def self.company_name(code)
25
+ company = @@companies[code]
26
+
27
+ if company.nil?
28
+ raise CompanyException, "証券コードに対応する会社が存在しない"
29
+ else
30
+ company
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ module Cub
2
+ VERSION = "0.0.1"
3
+ end
data/spec/cub_spec.rb ADDED
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'cub'
4
+ require 'yaml'
5
+
6
+ describe Cub do
7
+ context '証券コードに対応する会社が存在する場合' do
8
+ it '会社名を表示' do
9
+ Cub.company(7203).should eq('トヨタ自動車')
10
+ end
11
+ end
12
+
13
+ context '証券コードに対応する会社が存在しない場合' do
14
+ it '例外を返す' do
15
+ lambda{ Cub.company(0000) }.should raise_error(Cub::CompanyException)
16
+ end
17
+ end
18
+
19
+ context '証券コードが無効な場合' do
20
+ it '例外を返す' do
21
+ lambda{ Cub.company(333) }.should raise_error(Cub::CompanyException)
22
+ lambda{ Cub.company(55555) }.should raise_error(Cub::CompanyException)
23
+ lambda{ Cub.company('abcd') }.should raise_error(Cub::CompanyException)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.color_enabled = true
5
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - kano4
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Cub fetches stock information.
31
+ email:
32
+ - shinji.warp@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - companies.yml
43
+ - cub.gemspec
44
+ - lib/cub.rb
45
+ - lib/cub/version.rb
46
+ - spec/cub_spec.rb
47
+ - spec/spec_helper.rb
48
+ homepage: https://github.com/kano4/cub
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Fetch stock information
72
+ test_files:
73
+ - spec/cub_spec.rb
74
+ - spec/spec_helper.rb