histock-simplefilter 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 537696d001c6e3148c78257e5b52f9214e963e7f0782d461fab86d12a81c1fa7
4
+ data.tar.gz: f4f9266f19e365afd6822adb397cde21ad6343c7b7e883e91e207ee5668322e8
5
+ SHA512:
6
+ metadata.gz: 60ce4b2bc2b93be663d1d887710ceb993774bf94206e3e56521140f638e13cd35dea8d2e1b5a85b15fce7694937e0ab07bf59c2f6265c08a612f26026e408574
7
+ data.tar.gz: e04d83a9e16a9f8c3f38aa8b89db6e35d3a4905c87544cca8142923c5d71ef95aee5158b54abf878d37c6bd264fedb7b6eb81a7bdd160935e561ac613f81d952
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /coverage/
2
+ /pkg/
3
+ .rspec_status
4
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.8
6
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.1.0
2
+
3
+ * first beta release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in histock-simplefilter.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Yuya Sato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Histock::Simplefilter
2
+
3
+ [HiStock嗨投資理財社群](https://histock.tw/) filter by Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'histock-simplefilter'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install histock-simplefilter
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ # histock-simplefilter
28
+
29
+ ```rb
30
+ histock = Histock::Simplefilter.new
31
+ histock.dividend_policy(:code => '1234')
32
+ # [
33
+ # ["所屬年度", "發放年度", "除權日", "除息日", "除權息前股價", "股票股利", "現金股利", "EPS", "配息率", "現金殖利率", "扣抵稅率", "增資配股率", "增資認購價"],
34
+ # ["2019", "2020", "-", "06/18", "297.5", "0", "2.5", "13.32", "0.1877", "0.0084", "0", "0", "0"],
35
+ # ["2019", "2020", "-", "03/19", "260", "0", "2.5", "13.32", "0.1877", "0.0096", "0", "0", "0"],
36
+ # ["2018", "2019", "-", "12/19", "344.5", "0", "2.5", "13.54", "0.1846", "0.0073", "0", "0", "0"],
37
+ # ["2018", "2019", "-", "09/19", "267", "0", "2", "13.54", "0.1477", "0.0075", "0", "0", "0"],
38
+ # ["2018", "2019", "-", "06/24", "248.5", "0", "8", "13.54", "0.5908", "0.0322", "0", "0", "0"],
39
+ # ["2017", "2018", "-", "06/25", "227.5", "0", "8", "13.23", "0.6047", "0.0352", "0", "0", "0"],
40
+ # ["2016", "2017", "-", "06/26", "217", "0", "7", "12.89", "0.5431", "0.0323", "0.1394", "0", "0"],
41
+ # ["2015", "2016", "-", "06/27", "159", "0", "6", "11.82", "0.5076", "0.0377", "0.1257", "0", "0"],
42
+ # ["2014", "2015", "-", "06/29", "146", "0", "4.5", "10.18", "0.442", "0.0308", "0.1113", "0", "0"],
43
+ # ["2013", "2014", "-", "07/14", "136.5", "0", "3", "7.26", "0.4132", "0.022", "0.0978", "0", "0"],
44
+ # ["2012", "2013", "-", "07/03", "110", "0", "3", "6.41", "0.468", "0.0273", "0.0775", "0", "0"],
45
+ # ["2011", "2012", "-", "07/04", "84.2", "0", "3", "5.18", "0.5792", "0.0356", "0.0669", "0", "0"],
46
+ # ["2010", "2011", "-", "06/29", "72.5", "0", "3", "6.24", "0.4808", "0.0414", "0.0496", "0", "0"],
47
+ # ["2009", "2010", "-", "07/06", "61.4", "0", "3", "3.45", "0.8696", "0.0489", "0.0985", "0", "0"],
48
+ # ["2008", "2009", "07/15", "07/15", "55.8", "0.05", "3", "3.86", "0.7772", "0.0538", "0", "0", "0"],
49
+ # ["2007", "2008", "07/16", "07/16", "55.8", "0.05", "3.03", "-", "-", "0", "0.0186", "0.02", "0"]
50
+ # ]
51
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'histock/simplefilter'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ require_relative 'lib/histock/simplefilter/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'histock-simplefilter'
5
+ spec.version = Histock::Simplefilter::VERSION
6
+ spec.authors = ['yuya sato']
7
+ spec.email = ['ysato.5654@gmail.com']
8
+
9
+ spec.summary = 'HiStock (https://histock.tw/) filter'
10
+ spec.homepage = 'https://github.com/ysato5654/histock-simplefilter'
11
+ spec.license = 'MIT'
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata['homepage_uri'] = spec.homepage
15
+ spec.metadata['source_code_uri'] = 'https://github.com/ysato5654/histock-simplefilter'
16
+ spec.metadata['changelog_uri'] = 'https://github.com/ysato5654/histock-simplefilter/blob/master/CHANGELOG.md'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.required_ruby_version = '~> 2.5'
28
+
29
+ spec.add_runtime_dependency 'nokogiri', '~> 1.10.0'
30
+
31
+ spec.add_development_dependency 'bundler', '~> 2.0'
32
+ spec.add_development_dependency 'rake', '>= 12.3.3'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'travis', '>= 1.9.0'
35
+ end
@@ -0,0 +1,29 @@
1
+ require 'open-uri'
2
+
3
+ module Histock
4
+ module Connection
5
+ def get(path, **params)
6
+ request(path, params)
7
+ end
8
+
9
+ private
10
+
11
+ def request(path, params)
12
+ connection(path, params)
13
+ end
14
+
15
+ def connection(path, params)
16
+ @url = Simplefilter::BASE_URL + path + '?' + params.map { |key, val| [key, val].join('=') }.join('&')
17
+
18
+ @charset = nil
19
+ html = open(@url) do |f|
20
+ @charset = f.charset
21
+ f.read
22
+ end
23
+
24
+ @charset = html.scan(/charset="?([^\s"]*)/i).first.join if @charset.nil?
25
+
26
+ html
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ module Histock
2
+ class Error < StandardError
3
+ end
4
+
5
+ class InformationNotFound < Error; end
6
+
7
+ class XMLNodeSetError < Error; end
8
+
9
+ class TableFormatError < Error; end
10
+ class TableHeaderError < Error; end
11
+ class TableBodyError < Error; end
12
+ end
@@ -0,0 +1,10 @@
1
+ module Histock
2
+ module Fetch
3
+ module DividendPolicy
4
+ def dividend_policy(code)
5
+ params = {:no => code, :t => 2}
6
+ parse(:query => __method__, :html => get('/financial.aspx', params))
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,80 @@
1
+ require 'nokogiri'
2
+ require 'fetch/dividend_policy'
3
+
4
+ module Histock
5
+ module Fetch
6
+ include DividendPolicy
7
+
8
+ private
9
+
10
+ def parse query:, html:
11
+ doc = Nokogiri::HTML.parse(html, nil, @charset)
12
+ # => Nokogiri::HTML::Document
13
+
14
+ nodes = doc.xpath("//div[@class='row-stock']/div[@class='tb-outline']/table[@class='tb-stock text-center tbBasic']")
15
+ # => Nokogiri::XML::NodeSet
16
+
17
+ raise InformationNotFound if nodes.empty?
18
+ raise XMLNodeSetError unless nodes.length.is_one?
19
+
20
+ node = nodes.first
21
+ # => Nokogiri::XML::Element
22
+
23
+ array = []
24
+
25
+ node.children.each do |e|
26
+ next unless e.element?
27
+
28
+ case e.name
29
+ when 'tr'
30
+ value = parse_th(query: query, element: e)
31
+
32
+ array.push value unless value.empty?
33
+ else
34
+ raise TableFormatError
35
+ end
36
+ end
37
+
38
+ array
39
+ end
40
+
41
+ def parse_th query:, element:
42
+ value = Array.new
43
+
44
+ element.children.each do |e|
45
+ case e.name
46
+ when 'th' then value.push e.children.to_s.gsub(/\<br\>/, '')
47
+ when 'td' then value.push e.children.to_s
48
+ else puts e.name; raise TableFormatError
49
+ end
50
+ end
51
+
52
+ value
53
+ end
54
+ end
55
+ end
56
+
57
+ class Integer
58
+ def is_zero?
59
+ self == 0
60
+ end
61
+
62
+ def is_one?
63
+ self == 1
64
+ end
65
+ end
66
+
67
+ class String
68
+ def is_currency?
69
+ (self =~ /^[+-]?[0-9]*[\,]?[0-9]*[\.]?[0-9]+$/).nil? ? false : true
70
+ end
71
+
72
+ def to_currency
73
+ unless self.is_currency?
74
+ STDERR.puts "#{__FILE__}:#{__LINE__}: argument - #{self}"
75
+ raise ArgumentError
76
+ end
77
+
78
+ self.gsub(/[\,]/, '').to_f
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module Histock
2
+ class Simplefilter
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require 'simplefilter/version'
2
+ require 'simplefilter/connection'
3
+ require 'simplefilter/fetch'
4
+
5
+ module Histock
6
+ class Simplefilter
7
+ include Connection
8
+ include Fetch
9
+
10
+ BASE_URL = 'https://histock.tw/stock'
11
+
12
+ def initialize
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: histock-simplefilter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yuya sato
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 12.3.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 12.3.3
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: travis
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.0
83
+ description:
84
+ email:
85
+ - ysato.5654@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - histock-simplefilter.gemspec
101
+ - lib/histock/simplefilter.rb
102
+ - lib/histock/simplefilter/connection.rb
103
+ - lib/histock/simplefilter/error.rb
104
+ - lib/histock/simplefilter/fetch.rb
105
+ - lib/histock/simplefilter/fetch/dividend_policy.rb
106
+ - lib/histock/simplefilter/version.rb
107
+ homepage: https://github.com/ysato5654/histock-simplefilter
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ homepage_uri: https://github.com/ysato5654/histock-simplefilter
112
+ source_code_uri: https://github.com/ysato5654/histock-simplefilter
113
+ changelog_uri: https://github.com/ysato5654/histock-simplefilter/blob/master/CHANGELOG.md
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '2.5'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.1.2
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: HiStock (https://histock.tw/) filter
133
+ test_files: []