cub 0.0.2 → 0.0.3

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,6 +24,9 @@ Or install it yourself as:
24
24
  Cub.price(7203)
25
25
  => 3275
26
26
 
27
+ Cub.price(7203)
28
+ => 35.86
29
+
27
30
  ## Contributing
28
31
 
29
32
  1. Fork it
data/lib/cub/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cub
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/cub.rb CHANGED
@@ -26,6 +26,14 @@ module Cub
26
26
  end
27
27
  end
28
28
 
29
+ def self.per(code)
30
+ if valid_code?(code)
31
+ fetch_per(code)
32
+ else
33
+ raise CompanyException, "無効な証券コード"
34
+ end
35
+ end
36
+
29
37
  private
30
38
  def self.valid_code?(code)
31
39
  /^\d{4}$/ =~ code.to_s
@@ -48,4 +56,11 @@ module Cub
48
56
  doc.css('td[class=stoksPrice]').text.gsub(/(\d{0,3}),(\d{3})/, '\1\2').to_i
49
57
  end
50
58
 
59
+ def self.fetch_per(code)
60
+ url = "http://stocks.finance.yahoo.co.jp/stocks/detail/?code=#{code}"
61
+ user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)'
62
+ doc = Nokogiri::HTML(open(url, 'User-Agent' => user_agent).read)
63
+ doc.css('div[class=chartFinance] dl[class=tseDtl] dd[class="ymuiEditLink mar0"] strong').children[2].text.gsub(/\((連|単)\) /, "").to_f
64
+ end
65
+
51
66
  end
data/spec/cub_spec.rb CHANGED
@@ -11,6 +11,16 @@ describe Cub do
11
11
  it '株価を表示' do
12
12
  Cub.price(7203).should be_within(1000).of(3000)
13
13
  end
14
+
15
+ describe 'PERを表示' do
16
+ it '連結の場合' do
17
+ Cub.per(7203).should be > 0
18
+ end
19
+
20
+ it '単独の場合' do
21
+ Cub.per(3793).should be > 0
22
+ end
23
+ end
14
24
  end
15
25
 
16
26
  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.2
4
+ version: 0.0.3
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-20 00:00:00.000000000 Z
12
+ date: 2012-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri