sbi-security 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5a52e93b0f44800d5b20d5b18288b611a75293b
4
- data.tar.gz: aadab8393e8acad59b43589188fc451e944cea9c
3
+ metadata.gz: d73397285cf7f9d4161679ef56dd8560f7e54d7e
4
+ data.tar.gz: 1ec53a44798377bf9a5cf3ccc8f609860e8609b0
5
5
  SHA512:
6
- metadata.gz: f3cd1c0b7242de18017498892581bb5c5544b2a4dc16be1d68f418a9d5b585e7181389097ce943d317a419b29f7d845cda6fc41ac665e293e7a12bba4dd43888
7
- data.tar.gz: 70f066162c81b9aa0c7a5e8c7220a36dc26b4f23224a168d48738995eb2b545e0446f7595f1cb4612f5db22bee33b186d1cb82c8d8e86428f4cf70822db5cace
6
+ metadata.gz: 56e12fdcf31161f47678fd62a6019b241eadd83acce0676264053ab6d8082a35ec336e23422b6ad1b87c9ddd1ecbef1eee953186200d773becc5e19d9bb88cfc
7
+ data.tar.gz: 3344d204d76a698457e975d5a18935046b9e4a4e1ba2cd2507a0c38ba54aa1d0275fd13842126a3c276325176c07e075abdf3fcf79eb7d53319851af55515cd4
data/README.md CHANGED
@@ -26,8 +26,9 @@ Note: You need to set environment variables `SBI_SECURITY_USER_ID` and `SBI_SECU
26
26
 
27
27
  ### Show portfolio
28
28
 
29
- ```
30
- sbisec
29
+ ```bash
30
+ $ sbisec portfolio
31
+
31
32
  +--------+--------------+------+----------+--------+--------+---------+---------+----------+-----------+
32
33
  | コード | 銘柄 | 数量 | 参考単価 | 現在値 | 前日比 | 前日(%) | 損益 | 損益(%) | 評価額 |
33
34
  +--------+--------------+------+----------+--------+--------+---------+---------+----------+-----------+
@@ -40,7 +41,7 @@ sbisec
40
41
  - Implement `Sbi::Security::Client#buy`
41
42
  - Implement `Sbi::Security::Client#sell`
42
43
  - Update cli options
43
- - Like `sbisec portfolio` and `sbisec buy 3633 100`
44
+ - Like `sbisec buy 3633 3300 100` and `sbisec sell 3633 3000 100`
44
45
  - Add test
45
46
 
46
47
  ## Contributing
data/bin/sbisec CHANGED
@@ -2,31 +2,20 @@
2
2
  $:.unshift File.expand_path('../../lib', __FILE__)
3
3
 
4
4
  require 'sbi/security'
5
- require 'sbi/security/format'
6
- require 'terminal-table'
7
- require 'colorize'
5
+ require 'commander'
8
6
 
9
- include Sbi::Security::Format
7
+ Commander.configure do
8
+ program :name, 'CLI for SBI Security'
9
+ program :version, Sbi::Security::VERSION
10
+ program :description, 'You can check your portfolio.'
10
11
 
11
- client = Sbi::Security::Client.new(ENV["SBI_SECURITY_USER_ID"], ENV["SBI_SECURITY_PASSWORD"])
12
-
13
- rows = []
14
- rows << %w(コード 銘柄 数量 参考単価 現在値 前日比 前日(%) 損益 損益(%) 評価額)
15
- rows << :separator
16
- client.portfolio.stocks.each do |stock|
17
- rows << [
18
- stock.code,
19
- stock.name,
20
- number_to_currency(stock.count),
21
- number_to_currency(stock.value),
22
- number_to_currency(stock.price),
23
- format(stock.price_ratio),
24
- format(stock.price_ratio_percentage),
25
- format(stock.profit),
26
- format(stock.profit_percentage),
27
- number_to_currency(stock.total_value)
28
- ]
12
+ command :portfolio do |c|
13
+ c.syntax = 'sbisec portfolio'
14
+ c.description = 'Display your portfolio'
15
+ c.action do |args, options|
16
+ puts Sbi::Security::CLI.new(ENV["SBI_SECURITY_USER_ID"], ENV["SBI_SECURITY_PASSWORD"]).portfolio
17
+ end
18
+ end
29
19
  end
30
20
 
31
- puts Terminal::Table.new(rows: rows)
32
21
  exit 0
@@ -0,0 +1,20 @@
1
+ module Sbi::Security
2
+ class CLI
3
+ def initialize(user_id, password)
4
+ @client = Sbi::Security::Client.new(user_id, password)
5
+ end
6
+
7
+ def portfolio
8
+ portfolio = @client.portfolio
9
+
10
+ rows = []
11
+ rows << portfolio.decorate.header
12
+ rows << :separator
13
+ portfolio.stocks.each do |stock|
14
+ rows << stock.decorate.format
15
+ end
16
+
17
+ Terminal::Table.new(rows: rows)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Sbi::Security
2
+ class PortfolioDecorator < SimpleDelegator
3
+ def header
4
+ %w(コード 銘柄 数量 参考単価 現在値 前日比 前日(%) 損益 損益(%) 評価額)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module Sbi::Security
2
+ class StockDecorator < SimpleDelegator
3
+ include Sbi::Security::Formatter
4
+
5
+ def format
6
+ [
7
+ code,
8
+ name,
9
+ currency(count),
10
+ currency(value),
11
+ currency(price),
12
+ sign(price_ratio),
13
+ sign(price_ratio_percentage),
14
+ sign(profit),
15
+ sign(profit_percentage),
16
+ currency(total_value)
17
+ ]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Sbi::Security
2
+ module Decorator
3
+ def decorate
4
+ Object.const_get("#{self.class}Decorator").new(self)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module Sbi::Security
2
+ module Formatter
3
+ def currency(number)
4
+ number.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,')
5
+ end
6
+
7
+ def sign(number)
8
+ if number.to_i == 0
9
+ number.to_s
10
+ elsif number < 0
11
+ currency(number).colorize(:blue)
12
+ else
13
+ "+#{currency(number)}".colorize(:red)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,7 @@
1
1
  module Sbi::Security
2
2
  class Portfolio
3
+ include Decorator
4
+
3
5
  attr_reader :stocks
4
6
 
5
7
  def initialize(stocks)
@@ -1,5 +1,6 @@
1
1
  module Sbi::Security
2
2
  class Stock
3
+ include Decorator
3
4
  include Virtus.model(strict: true)
4
5
 
5
6
  attribute :code, Integer
@@ -1,5 +1,5 @@
1
1
  module Sbi
2
2
  module Security
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/lib/sbi/security.rb CHANGED
@@ -2,7 +2,8 @@ require "capybara"
2
2
  require 'capybara/dsl'
3
3
  require 'selenium-webdriver'
4
4
  require 'virtus'
5
- require 'money'
5
+ require 'terminal-table'
6
+ require 'colorize'
6
7
 
7
8
  module Sbi
8
9
  module Security
@@ -10,7 +11,12 @@ module Sbi
10
11
  end
11
12
 
12
13
  require "sbi/security/client"
14
+ require "sbi/security/cli"
13
15
  require "sbi/security/crawler"
16
+ require "sbi/security/formatter"
17
+ require "sbi/security/decorator"
18
+ require "sbi/security/decorator/portfolio_decorator"
19
+ require "sbi/security/decorator/stock_decorator"
14
20
  require "sbi/security/portfolio"
15
21
  require "sbi/security/stock"
16
22
  require "sbi/security/version"
data/sbi-security.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "virtus", "~> 1.0"
25
25
  spec.add_dependency "terminal-table", "~> 1.8"
26
26
  spec.add_dependency "colorize", "~> 0.8"
27
+ spec.add_dependency "commander", "~> 4.4"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.15"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbi-security
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - camelmasa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: commander
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.4'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -138,9 +152,13 @@ files:
138
152
  - Rakefile
139
153
  - bin/sbisec
140
154
  - lib/sbi/security.rb
155
+ - lib/sbi/security/cli.rb
141
156
  - lib/sbi/security/client.rb
142
157
  - lib/sbi/security/crawler.rb
143
- - lib/sbi/security/format.rb
158
+ - lib/sbi/security/decorator.rb
159
+ - lib/sbi/security/decorator/portfolio_decorator.rb
160
+ - lib/sbi/security/decorator/stock_decorator.rb
161
+ - lib/sbi/security/formatter.rb
144
162
  - lib/sbi/security/portfolio.rb
145
163
  - lib/sbi/security/stock.rb
146
164
  - lib/sbi/security/version.rb
@@ -1,19 +0,0 @@
1
- module Sbi::Security
2
- module Format
3
- def format(number)
4
- if number.nil? || number == 0
5
- return number.to_s
6
- end
7
-
8
- if number > 0
9
- "+#{number_to_currency(number)}".colorize(:red)
10
- else
11
- "#{number_to_currency(number)}".colorize(:blue)
12
- end
13
- end
14
-
15
- def number_to_currency(number)
16
- number.to_s.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\1,')
17
- end
18
- end
19
- end