cub 0.0.3 → 0.0.4

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/README.md CHANGED
@@ -24,9 +24,12 @@ Or install it yourself as:
24
24
  Cub.price(7203)
25
25
  => 3275
26
26
 
27
- Cub.price(7203)
27
+ Cub.per(7203)
28
28
  => 35.86
29
29
 
30
+ Cub.pbr(7203)
31
+ => 0.97
32
+
30
33
  ## Contributing
31
34
 
32
35
  1. Fork it
data/lib/cub.rb CHANGED
@@ -34,6 +34,14 @@ module Cub
34
34
  end
35
35
  end
36
36
 
37
+ def self.pbr(code)
38
+ if valid_code?(code)
39
+ fetch_pbr(code)
40
+ else
41
+ raise CompanyException, "無効な証券コード"
42
+ end
43
+ end
44
+
37
45
  private
38
46
  def self.valid_code?(code)
39
47
  /^\d{4}$/ =~ code.to_s
@@ -63,4 +71,11 @@ module Cub
63
71
  doc.css('div[class=chartFinance] dl[class=tseDtl] dd[class="ymuiEditLink mar0"] strong').children[2].text.gsub(/\((連|単)\) /, "").to_f
64
72
  end
65
73
 
74
+ def self.fetch_pbr(code)
75
+ url = "http://stocks.finance.yahoo.co.jp/stocks/detail/?code=#{code}"
76
+ user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)'
77
+ doc = Nokogiri::HTML(open(url, 'User-Agent' => user_agent).read)
78
+ doc.css('div[class=chartFinance] dl[class=tseDtl] dd[class="ymuiEditLink mar0"] strong').children[3].text.gsub(/\((連|単)\) /, "").to_f
79
+ end
80
+
66
81
  end
@@ -1,3 +1,3 @@
1
1
  module Cub
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -21,6 +21,16 @@ describe Cub do
21
21
  Cub.per(3793).should be > 0
22
22
  end
23
23
  end
24
+
25
+ describe 'PBRを表示' do
26
+ it '連結の場合' do
27
+ Cub.pbr(7203).should be > 0
28
+ end
29
+
30
+ it '単独の場合' do
31
+ Cub.pbr(3793).should be > 0
32
+ end
33
+ end
24
34
  end
25
35
 
26
36
  context '証券コードに対応する会社が存在しない場合' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-25 00:00:00.000000000 Z
12
+ date: 2012-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri