finviz 0.2.1 → 0.3.0

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
  SHA256:
3
- metadata.gz: 502c9e1ace1fd59f808968ba26d2ff82a74d03b3ca6579d0e65549c7c899fe1c
4
- data.tar.gz: fc16bb8fe275c381ab3c5b76c084d05467fa2e5de416dcb02f2be68ba939653e
3
+ metadata.gz: 835b79336936f1465a97e86c3a82ea4f8d4011b0c0dc4fed645a5d7abef53556
4
+ data.tar.gz: 56f0e86206d7d7706adb321e4522adb08cd19d13435a5a2fc3acdf296c7481cc
5
5
  SHA512:
6
- metadata.gz: 3fc3232cd15163ad2394e3242477573c81914f9f99db9fbaba9a2caefbaf0b7b2234c4d9518ca1a1891c7fc75f7e73eb22fe7085f21ef19da967029f31e8f426
7
- data.tar.gz: a2b1a12d9d9c2177b70d0c5e72facaa2b24a90ae95b684840b7fe0aa1632071f898f340702033e6e190b09d0f80cf1687ea36d1c0e03fa5e977a838d99c4d58b
6
+ metadata.gz: d3cd8314b97d13589148ffd829c532debc4ec48d43c61a9d8f48d090bca2c09fc13206d5f372b7ed46f225148880980a90b795e9b9410647d234ec36c10cfc3e
7
+ data.tar.gz: adc4acfc82ac05864a10c6f06d5825cadeec2b271f8be7b4ecee295eea60d2322df43805c8644ec6cacfe7b5deb311e3b1149ec4fd3b9d026cccb87761174791
data/.rubocop.yml CHANGED
@@ -16,6 +16,3 @@ Layout/LineLength:
16
16
  Metrics/BlockLength:
17
17
  Exclude:
18
18
  - spec/**/*
19
-
20
- Metrics/AbcSize:
21
- Max: 18
data/CHANGELOG.md CHANGED
@@ -12,3 +12,7 @@
12
12
  ## [0.2.1] - 2021-05-17
13
13
 
14
14
  - Add path to quotes fetcher output
15
+
16
+ ## [0.3.0] - 2021-05-19
17
+
18
+ - Quotes fetcher refactoring. `QuotesFetcher.call` Output syntax changed.
data/README.md CHANGED
@@ -44,166 +44,173 @@ Finviz.tickers filters: %w[fa_pe_u5 sh_price_u3]
44
44
 
45
45
  ### Fetch quotes
46
46
 
47
- Each quote contain the Hash with ticker stats and link to the chart picture, see
47
+ Each quote contain the OpenStruct with ticker stats and links to the ticker and chart, see
48
48
  example:
49
49
 
50
50
  ```ruby
51
- quotes = Finviz.quotes tickers: %w[a c]
52
- => [#<OpenStruct path="https://finviz.com/quote.ashx?t=A", ticker="A", chart="https://charts2.finviz.com/chart.ashx?t=C&ty=c&ta=1&p=d&s=l", stats={"Index"=>"S&P 500", "P/E"=>"50.35", "EPS (ttm)"=>"2.60", "Insider Own"=>"0.30%", "Shs Outstand"=>"306.00M", "Perf Week"=>"-2.05%", "Market Cap"=>"39.62B", "Forward P/E"=>"30.11", "EPS next Y"=>"11.78%", "Insider Trans"=>"-21.60%", "Shs Float"=>"303.84M", "Perf Month"=>"-1.60%", "Income"=>"810.00M", "PEG"=>"4.66", "EPS next Q"=>"0.83", "Inst Own"=>"91.60%", "Short Float"=>"0.70%", "Perf Quarter"=>"2.48%", "Sales"=>"5.53B", "P/S"=>"7.16", "EPS this Y"=>"-31.60%", "Inst Trans"=>"0.76%", "Short Ratio"=>"1.31", "Perf Half Y"=>"19.87%", "Book/sh"=>"15.70", "P/B"=>"8.35", "ROA"=>"8.50%", "Target Price"=>"140.23", "Perf Year"=>"60.64%", "Cash/sh"=>"4.40", "P/C"=>"29.81", "EPS next 5Y"=>"10.80%", "ROE"=>"16.70%", "52W Range"=>"80.46 - 137.83", "Perf YTD"=>"10.68%", "Dividend"=>"0.78", "P/FCF"=>"45.69", "EPS past 5Y"=>"12.00%", "ROI"=>"10.00%", "52W High"=>"-5.40%", "Beta"=>"1.01", "Dividend %"=>"0.59%", "Quick Ratio"=>"1.60", "Sales past 5Y"=>"5.70%", "Gross Margin"=>"53.30%", "52W Low"=>"62.05%", "ATR"=>"2.09", "Employees"=>"16400", "Current Ratio"=>"2.10", "Sales Q/Q"=>"14.10%", "Oper. Margin"=>"17.30%", "RSI (14)"=>"47.00", "Volatility"=>"1.56% 1.40%", "Optionable"=>"Yes", "Debt/Eq"=>"0.52", "EPS Q/Q"=>"48.10%", "Profit Margin"=>"14.60%", "Rel Volume"=>"0.31", "Prev Close"=>"131.15", "Shortable"=>"Yes", "LT Debt/Eq"=>"0.45", "Earnings"=>"May 25 AMC", "Payout"=>"27.40%", "Avg Volume"=>"1.63M", "Price"=>"130.38", "Recom"=>"1.90", "SMA20"=>"-2.12%", "SMA50"=>"1.38%", "SMA200"=>"13.08%", "Volume"=>"303,128", "Change"=>"-0.58%"}>,
53
- #<OpenStruct path="https://finviz.com/quote.ashx?t=C", ticker="C", chart="https://charts2.finviz.com/chart.ashx?t=C&ty=c&ta=1&p=d&s=l", stats={"Index"=>"S&P 500", "P/E"=>"10.50", "EPS (ttm)"=>"7.29", "Insider Own"=>"0.20%", "Shs Outstand"=>"2.08B", "Perf Week"=>"1.97%", "Market Cap"=>"155.63B", "Forward P/E"=>"9.32", "EPS next Y"=>"-8.81%", "Insider Trans"=>"-1.30%", "Shs Float"=>"2.04B", "Perf Month"=>"5.54%", "Income"=>"15.26B", "PEG"=>"0.96", "EPS next Q"=>"2.00", "Inst Own"=>"78.80%", "Short Float"=>"1.20%", "Perf Quarter"=>"20.32%", "Sales"=>"53.48B", "P/S"=>"2.91", "EPS this Y"=>"-41.10%", "Inst Trans"=>"0.52%", "Short Ratio"=>"1.27", "Perf Half Y"=>"56.47%", "Book/sh"=>"87.55", "P/B"=>"0.87", "ROA"=>"0.70%", "Target Price"=>"85.23", "Perf Year"=>"82.03%", "Cash/sh"=>"486.62", "P/C"=>"0.16", "EPS next 5Y"=>"10.91%", "ROE"=>"8.60%", "52W Range"=>"40.49 - 76.84", "Perf YTD"=>"24.16%", "Dividend"=>"2.04", "P/FCF"=>"7.76", "EPS past 5Y"=>"-2.70%", "ROI"=>"6.80%", "52W High"=>"0.35%", "Beta"=>"1.90", "Dividend %"=>"2.66%", "Quick Ratio"=>"-", "Sales past 5Y"=>"-0.20%", "Gross Margin"=>"-", "52W Low"=>"90.44%", "ATR"=>"1.72", "Employees"=>"211000", "Current Ratio"=>"-", "Sales Q/Q"=>"-26.90%", "Oper. Margin"=>"64.00%", "RSI (14)"=>"67.10", "Volatility"=>"2.44% 2.21%", "Optionable"=>"Yes", "Debt/Eq"=>"2.70", "EPS Q/Q"=>"240.40%", "Profit Margin"=>"28.50%", "Rel Volume"=>"0.73", "Prev Close"=>"76.56", "Shortable"=>"Yes", "LT Debt/Eq"=>"1.35", "Earnings"=>"Apr 15 BMO", "Payout"=>"27.80%", "Avg Volume"=>"19.41M", "Price"=>"77.11", "Recom"=>"2.10", "SMA20"=>"5.58%", "SMA50"=>"5.98%", "SMA200"=>"31.27%", "Volume"=>"8,396,127", "Change"=>"0.72%"}>]
54
-
55
- # The same in more human friendly view:
56
- Pry::ColorPrinter.pp(quotes.map(&:to_h))
57
- => [{:path=>"https://finviz.com/quote.ashx?t=A",
58
- :ticker=>"A",
59
- :chart=>"https://charts2.finviz.com/chart.ashx?t=C&ty=c&ta=1&p=d&s=l",
60
- :stats=>
61
- {"Index"=>"S&P 500",
62
- "P/E"=>"50.35",
63
- "EPS (ttm)"=>"2.60",
64
- "Insider Own"=>"0.30%",
65
- "Shs Outstand"=>"306.00M",
66
- "Perf Week"=>"-2.05%",
67
- "Market Cap"=>"39.62B",
68
- "Forward P/E"=>"30.11",
69
- "EPS next Y"=>"11.78%",
70
- "Insider Trans"=>"-21.60%",
71
- "Shs Float"=>"303.84M",
72
- "Perf Month"=>"-1.60%",
73
- "Income"=>"810.00M",
74
- "PEG"=>"4.66",
75
- "EPS next Q"=>"0.83",
76
- "Inst Own"=>"91.60%",
77
- "Short Float"=>"0.70%",
78
- "Perf Quarter"=>"2.48%",
79
- "Sales"=>"5.53B",
80
- "P/S"=>"7.16",
81
- "EPS this Y"=>"-31.60%",
82
- "Inst Trans"=>"0.76%",
83
- "Short Ratio"=>"1.31",
84
- "Perf Half Y"=>"19.87%",
85
- "Book/sh"=>"15.70",
86
- "P/B"=>"8.35",
87
- "ROA"=>"8.50%",
88
- "Target Price"=>"140.23",
89
- "Perf Year"=>"60.64%",
90
- "Cash/sh"=>"4.40",
91
- "P/C"=>"29.81",
92
- "EPS next 5Y"=>"10.80%",
93
- "ROE"=>"16.70%",
94
- "52W Range"=>"80.46 - 137.83",
95
- "Perf YTD"=>"10.68%",
96
- "Dividend"=>"0.78",
97
- "P/FCF"=>"45.69",
98
- "EPS past 5Y"=>"12.00%",
99
- "ROI"=>"10.00%",
100
- "52W High"=>"-5.40%",
101
- "Beta"=>"1.01",
102
- "Dividend %"=>"0.59%",
103
- "Quick Ratio"=>"1.60",
104
- "Sales past 5Y"=>"5.70%",
105
- "Gross Margin"=>"53.30%",
106
- "52W Low"=>"62.05%",
107
- "ATR"=>"2.09",
108
- "Employees"=>"16400",
109
- "Current Ratio"=>"2.10",
110
- "Sales Q/Q"=>"14.10%",
111
- "Oper. Margin"=>"17.30%",
112
- "RSI (14)"=>"47.00",
113
- "Volatility"=>"1.56% 1.40%",
114
- "Optionable"=>"Yes",
115
- "Debt/Eq"=>"0.52",
116
- "EPS Q/Q"=>"48.10%",
117
- "Profit Margin"=>"14.60%",
118
- "Rel Volume"=>"0.31",
119
- "Prev Close"=>"131.15",
120
- "Shortable"=>"Yes",
121
- "LT Debt/Eq"=>"0.45",
122
- "Earnings"=>"May 25 AMC",
123
- "Payout"=>"27.40%",
124
- "Avg Volume"=>"1.63M",
125
- "Price"=>"130.38",
126
- "Recom"=>"1.90",
127
- "SMA20"=>"-2.12%",
128
- "SMA50"=>"1.38%",
129
- "SMA200"=>"13.08%",
130
- "Volume"=>"303,128",
131
- "Change"=>"-0.58%"}},
132
- {:path=>"https://finviz.com/quote.ashx?t=C",
133
- :ticker=>"C",
134
- :chart=>"https://charts2.finviz.com/chart.ashx?t=C&ty=c&ta=1&p=d&s=l",
135
- :stats=>
136
- {"Index"=>"S&P 500",
137
- "P/E"=>"10.50",
138
- "EPS (ttm)"=>"7.29",
139
- "Insider Own"=>"0.20%",
140
- "Shs Outstand"=>"2.08B",
141
- "Perf Week"=>"1.97%",
142
- "Market Cap"=>"155.63B",
143
- "Forward P/E"=>"9.32",
144
- "EPS next Y"=>"-8.81%",
145
- "Insider Trans"=>"-1.30%",
146
- "Shs Float"=>"2.04B",
147
- "Perf Month"=>"5.54%",
148
- "Income"=>"15.26B",
149
- "PEG"=>"0.96",
150
- "EPS next Q"=>"2.00",
151
- "Inst Own"=>"78.80%",
152
- "Short Float"=>"1.20%",
153
- "Perf Quarter"=>"20.32%",
154
- "Sales"=>"53.48B",
155
- "P/S"=>"2.91",
156
- "EPS this Y"=>"-41.10%",
157
- "Inst Trans"=>"0.52%",
158
- "Short Ratio"=>"1.27",
159
- "Perf Half Y"=>"56.47%",
160
- "Book/sh"=>"87.55",
161
- "P/B"=>"0.87",
162
- "ROA"=>"0.70%",
163
- "Target Price"=>"85.23",
164
- "Perf Year"=>"82.03%",
165
- "Cash/sh"=>"486.62",
166
- "P/C"=>"0.16",
167
- "EPS next 5Y"=>"10.91%",
168
- "ROE"=>"8.60%",
169
- "52W Range"=>"40.49 - 76.84",
170
- "Perf YTD"=>"24.16%",
171
- "Dividend"=>"2.04",
172
- "P/FCF"=>"7.76",
173
- "EPS past 5Y"=>"-2.70%",
174
- "ROI"=>"6.80%",
175
- "52W High"=>"0.35%",
176
- "Beta"=>"1.90",
177
- "Dividend %"=>"2.66%",
178
- "Quick Ratio"=>"-",
179
- "Sales past 5Y"=>"-0.20%",
180
- "Gross Margin"=>"-",
181
- "52W Low"=>"90.44%",
182
- "ATR"=>"1.72",
183
- "Employees"=>"211000",
184
- "Current Ratio"=>"-",
185
- "Sales Q/Q"=>"-26.90%",
186
- "Oper. Margin"=>"64.00%",
187
- "RSI (14)"=>"67.10",
188
- "Volatility"=>"2.44% 2.21%",
189
- "Optionable"=>"Yes",
190
- "Debt/Eq"=>"2.70",
191
- "EPS Q/Q"=>"240.40%",
192
- "Profit Margin"=>"28.50%",
193
- "Rel Volume"=>"0.73",
194
- "Prev Close"=>"76.56",
195
- "Shortable"=>"Yes",
196
- "LT Debt/Eq"=>"1.35",
197
- "Earnings"=>"Apr 15 BMO",
198
- "Payout"=>"27.80%",
199
- "Avg Volume"=>"19.41M",
200
- "Price"=>"77.11",
201
- "Recom"=>"2.10",
202
- "SMA20"=>"5.58%",
203
- "SMA50"=>"5.98%",
204
- "SMA200"=>"31.27%",
205
- "Volume"=>"8,396,127",
206
- "Change"=>"0.72%"}}]
51
+ [1] pry(main)> quotes = Finviz.quotes tickers: %w[aapl mrna]
52
+
53
+ [2] pry(main)> quotes.m # If the quote was not requested
54
+ => nil
55
+
56
+ [3] pry(main)> quotes.aapl
57
+ => #<Finviz::Quote:0x00007fb7189895f0
58
+ @stats=
59
+ {"Index"=>"DJIA S&P500",
60
+ "P/E"=>"28.02",
61
+ "EPS (ttm)"=>"4.46",
62
+ "Insider Own"=>"0.07%",
63
+ "Shs Outstand"=>"16.75B",
64
+ "Perf Week"=>"-0.84%",
65
+ "Market Cap"=>"2042.91B",
66
+ "Forward P/E"=>"23.38",
67
+ "EPS next Y"=>"2.89%",
68
+ "Insider Trans"=>"-2.80%",
69
+ "Shs Float"=>"16.68B",
70
+ "Perf Month"=>"-7.41%",
71
+ "Income"=>"76.31B",
72
+ "PEG"=>"1.56",
73
+ "EPS next Q"=>"0.99",
74
+ "Inst Own"=>"59.90%",
75
+ "Short Float"=>"0.50%",
76
+ "Perf Quarter"=>"-4.58%",
77
+ "Sales"=>"325.41B",
78
+ "P/S"=>"6.28",
79
+ "EPS this Y"=>"10.20%",
80
+ "Inst Trans"=>"-0.49%",
81
+ "Short Ratio"=>"0.79",
82
+ "Perf Half Y"=>"4.69%",
83
+ "Book/sh"=>"4.13",
84
+ "P/B"=>"30.23",
85
+ "ROA"=>"22.90%",
86
+ "Target Price"=>"159.74",
87
+ "Perf Year"=>"58.56%",
88
+ "Cash/sh"=>"4.27",
89
+ "P/C"=>"29.25",
90
+ "EPS next 5Y"=>"17.93%",
91
+ "ROE"=>"111.80%",
92
+ "52W Range"=>"77.58 - 145.09",
93
+ "Perf YTD"=>"-5.91%",
94
+ "Dividend"=>"0.88",
95
+ "P/FCF"=>"26.79",
96
+ "EPS past 5Y"=>"7.30%",
97
+ "ROI"=>"31.70%",
98
+ "52W High"=>"-13.95%",
99
+ "Beta"=>"1.22",
100
+ "Dividend %"=>"0.70%",
101
+ "Quick Ratio"=>"1.10",
102
+ "Sales past 5Y"=>"3.30%",
103
+ "Gross Margin"=>"39.90%",
104
+ "52W Low"=>"60.93%",
105
+ "ATR"=>"2.90",
106
+ "Employees"=>"147000",
107
+ "Current Ratio"=>"1.10",
108
+ "Sales Q/Q"=>"53.60%",
109
+ "Oper. Margin"=>"27.30%",
110
+ "RSI (14)"=>"41.95",
111
+ "Volatility"=>"1.65% 2.00%",
112
+ "Optionable"=>"Yes",
113
+ "Debt/Eq"=>"1.76",
114
+ "EPS Q/Q"=>"118.60%",
115
+ "Profit Margin"=>"23.50%",
116
+ "Rel Volume"=>"0.60",
117
+ "Prev Close"=>"126.27",
118
+ "Shortable"=>"Yes",
119
+ "LT Debt/Eq"=>"1.57",
120
+ "Earnings"=>"Apr 28 AMC",
121
+ "Payout"=>"18.20%",
122
+ "Avg Volume"=>"104.09M",
123
+ "Price"=>"124.85",
124
+ "Recom"=>"2.00",
125
+ "SMA20"=>"-4.08%",
126
+ "SMA50"=>"-1.80%",
127
+ "SMA200"=>"1.15%",
128
+ "Volume"=>"62,545,117",
129
+ "Change"=>"-1.12%"},
130
+ @ticker="aapl">
131
+
132
+ [4] pry(main)> quotes.aapl.chart
133
+ => "https://charts2.finviz.com/chart.ashx?t=aapl&ty=c&ta=1&p=d&s=l"
134
+
135
+ [5] pry(main)> quotes.aapl.path
136
+ => "https://finviz.com/quote.ashx?t=aapl"
137
+
138
+ [6] pry(main)> quotes.aapl.to_h
139
+ => {:stats=>
140
+ {"Index"=>"DJIA S&P500",
141
+ "P/E"=>"28.02",
142
+ "EPS (ttm)"=>"4.46",
143
+ "Insider Own"=>"0.07%",
144
+ "Shs Outstand"=>"16.75B",
145
+ "Perf Week"=>"-0.84%",
146
+ "Market Cap"=>"2042.91B",
147
+ "Forward P/E"=>"23.38",
148
+ "EPS next Y"=>"2.89%",
149
+ "Insider Trans"=>"-2.80%",
150
+ "Shs Float"=>"16.68B",
151
+ "Perf Month"=>"-7.41%",
152
+ "Income"=>"76.31B",
153
+ "PEG"=>"1.56",
154
+ "EPS next Q"=>"0.99",
155
+ "Inst Own"=>"59.90%",
156
+ "Short Float"=>"0.50%",
157
+ "Perf Quarter"=>"-4.58%",
158
+ "Sales"=>"325.41B",
159
+ "P/S"=>"6.28",
160
+ "EPS this Y"=>"10.20%",
161
+ "Inst Trans"=>"-0.49%",
162
+ "Short Ratio"=>"0.79",
163
+ "Perf Half Y"=>"4.69%",
164
+ "Book/sh"=>"4.13",
165
+ "P/B"=>"30.23",
166
+ "ROA"=>"22.90%",
167
+ "Target Price"=>"159.74",
168
+ "Perf Year"=>"58.56%",
169
+ "Cash/sh"=>"4.27",
170
+ "P/C"=>"29.25",
171
+ "EPS next 5Y"=>"17.93%",
172
+ "ROE"=>"111.80%",
173
+ "52W Range"=>"77.58 - 145.09",
174
+ "Perf YTD"=>"-5.91%",
175
+ "Dividend"=>"0.88",
176
+ "P/FCF"=>"26.79",
177
+ "EPS past 5Y"=>"7.30%",
178
+ "ROI"=>"31.70%",
179
+ "52W High"=>"-13.95%",
180
+ "Beta"=>"1.22",
181
+ "Dividend %"=>"0.70%",
182
+ "Quick Ratio"=>"1.10",
183
+ "Sales past 5Y"=>"3.30%",
184
+ "Gross Margin"=>"39.90%",
185
+ "52W Low"=>"60.93%",
186
+ "ATR"=>"2.90",
187
+ "Employees"=>"147000",
188
+ "Current Ratio"=>"1.10",
189
+ "Sales Q/Q"=>"53.60%",
190
+ "Oper. Margin"=>"27.30%",
191
+ "RSI (14)"=>"41.95",
192
+ "Volatility"=>"1.65% 2.00%",
193
+ "Optionable"=>"Yes",
194
+ "Debt/Eq"=>"1.76",
195
+ "EPS Q/Q"=>"118.60%",
196
+ "Profit Margin"=>"23.50%",
197
+ "Rel Volume"=>"0.60",
198
+ "Prev Close"=>"126.27",
199
+ "Shortable"=>"Yes",
200
+ "LT Debt/Eq"=>"1.57",
201
+ "Earnings"=>"Apr 28 AMC",
202
+ "Payout"=>"18.20%",
203
+ "Avg Volume"=>"104.09M",
204
+ "Price"=>"124.85",
205
+ "Recom"=>"2.00",
206
+ "SMA20"=>"-4.08%",
207
+ "SMA50"=>"-1.80%",
208
+ "SMA200"=>"1.15%",
209
+ "Volume"=>"62,545,117",
210
+ "Change"=>"-1.12%"},
211
+ :path=>"https://finviz.com/quote.ashx?t=aapl",
212
+ :chart=>"https://charts2.finviz.com/chart.ashx?t=aapl&ty=c&ta=1&p=d&s=l",
213
+ :ticker=>"aapl"}
207
214
  ```
208
215
 
209
216
  ## Development
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/hash_with_indifferent_access"
4
+
5
+ module Finviz
6
+ # Single quote representation
7
+ class Quote
8
+ attr_reader :ticker, :stats
9
+
10
+ def initialize(ticker:, stats: nil)
11
+ @ticker = ticker
12
+ @stats = ActiveSupport::HashWithIndifferentAccess.new(stats.to_h)
13
+ end
14
+
15
+ def path
16
+ "https://finviz.com/quote.ashx?t=#{ticker}"
17
+ end
18
+
19
+ def chart
20
+ "https://charts2.finviz.com/chart.ashx?t=#{ticker}&ty=c&ta=1&p=d&s=l"
21
+ end
22
+
23
+ # grab all instance methods to the hash
24
+ def to_h
25
+ (self.class.instance_methods(false) - [__callee__]).each_with_object({}) do |method, acc|
26
+ acc[method] = public_send method
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Finviz
4
+ # The result of the quotes request
5
+ class Quotes < OpenStruct
6
+ def add_quote_from_xpath(ticker_xpath, table_xpath)
7
+ ticker = ticker_xpath.children.text.downcase
8
+ stats = table_xpath
9
+ .css(".table-dark-row")
10
+ .map { |row| row.css("td").map(&:text) }
11
+ .flatten
12
+ .each_slice(2)
13
+ self[ticker] = Quote.new ticker: ticker, stats: stats
14
+ end
15
+
16
+ def to_h
17
+ super.transform_values(&:to_h)
18
+ end
19
+ end
20
+ end
@@ -10,42 +10,16 @@ module Finviz
10
10
  attr_reader :tickers
11
11
 
12
12
  def call
13
- add_stats_to_results
14
- add_charts_to_results
15
- results.flatten!
16
- end
17
-
18
- private
19
-
20
- def add_stats_to_results
21
- all_pages.each_with_index do |page, page_number|
22
- page.html.css(".snapshot-table2").each_with_index do |xpath, selector_offset|
23
- current = results[page_number][selector_offset]
24
- current.stats = xpath.css(".table-dark-row").map { |row| row.css("td").map(&:text) }
25
- .flatten.each_slice(2).to_h
26
- end
27
- end
28
- end
29
-
30
- def add_charts_to_results
31
- all_pages.each_with_index do |page, page_number|
32
- page.html.css("#chart1").each_with_index do |xpath, selector_offset|
33
- current = results[page_number][selector_offset]
34
- current.chart = xpath.attributes["src"].text
13
+ Quotes.new.tap do |result|
14
+ all_pages.each do |page|
15
+ page.html.css("#ticker").zip(page.html.css(".snapshot-table2")).each do |(ticker_xpath, table_xpath)|
16
+ result.add_quote_from_xpath(ticker_xpath, table_xpath)
17
+ end
35
18
  end
36
19
  end
37
20
  end
38
21
 
39
- def results
40
- @results ||= all_pages.map do |page|
41
- page.html.css("#ticker").map do |xpath|
42
- ticker = xpath.children.text
43
- OpenStruct.new path: "https://finviz.com/quote.ashx?t=#{ticker}",
44
- ticker: ticker,
45
- chart: "https://charts2.finviz.com/chart.ashx?t=#{ticker}&ty=c&ta=1&p=d&s=l"
46
- end
47
- end
48
- end
22
+ private
49
23
 
50
24
  def all_pages
51
25
  @all_pages ||= Crawler.call(paths: paths)
@@ -38,12 +38,20 @@ module Finviz
38
38
 
39
39
  def normalize_uri(uri, filters)
40
40
  uri = URI(uri || base_uri)
41
- query = CGI.parse(uri.query || "").tap do |params|
42
- params["f"] = filters&.join(",") if filters&.any?
41
+
42
+ @uri = URI::HTTPS.build(
43
+ host: base_uri,
44
+ path: base_path,
45
+ query: CGI.unescape(URI.encode_www_form(query(uri, filters)))
46
+ )
47
+ end
48
+
49
+ def query(uri, filters)
50
+ CGI.parse(uri.query || "").tap do |params|
51
+ params["f"] = filters.join(",") if filters&.any?
43
52
  params["v"] = finviz_view_type
44
53
  params.delete("r") # remove offset if it was provided
45
54
  end
46
- @uri = URI::HTTPS.build(host: base_uri, path: base_path, query: CGI.unescape(URI.encode_www_form(query)))
47
55
  end
48
56
 
49
57
  def base_uri
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Finviz
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kvokka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-17 00:00:00.000000000 Z
11
+ date: 2021-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -102,6 +102,8 @@ files:
102
102
  - finviz.gemspec
103
103
  - lib/finviz.rb
104
104
  - lib/finviz/crawler.rb
105
+ - lib/finviz/quote.rb
106
+ - lib/finviz/quotes.rb
105
107
  - lib/finviz/quotes_fetcher.rb
106
108
  - lib/finviz/tickers_fetcher.rb
107
109
  - lib/finviz/version.rb