aadyandana-latest_stock_price 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/lib/aadyandana/latest_stock_price/version.rb +1 -1
- data/lib/aadyandana/latest_stock_price.rb +40 -10
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd38ba3dabb637a579797d9dbfa635bf84750a6e39ffbe98810d3665098b94ba
|
4
|
+
data.tar.gz: '0896beedbf3f06f69687b7b8e76f652f287cf776859911f61f6babe1322fc09c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82ee3b246f777fb1e677476e2d3c6306986745a131038117a1a98c1c5c729ff1b4fcab5922be281a5e0e71d39102b1c9cefb7be8ef240f3398c8a8460a778ea7
|
7
|
+
data.tar.gz: 75b8d8e31b7863237af447952fa92661b8883bf70de55452999d4d21c0018608ba1371f3db063d83f2c006b46abe4b5c7cc0bdb60fded4ba79a110b40dc451d0
|
data/CHANGELOG.md
CHANGED
@@ -27,6 +27,10 @@ module Aadyandana
|
|
27
27
|
def initialize(api_key, params = {})
|
28
28
|
@api_key = api_key
|
29
29
|
@params = params
|
30
|
+
|
31
|
+
@datetime_attrs = [ "lastUpdateTime" ]
|
32
|
+
@string_meta_attrs = [ "companyName", "industry", "isin" ]
|
33
|
+
@string_attrs = [ "identifier", "symbol" ] + @string_meta_attrs
|
30
34
|
end
|
31
35
|
|
32
36
|
def price
|
@@ -42,16 +46,21 @@ module Aadyandana
|
|
42
46
|
def prices
|
43
47
|
page = (@params[:page] || 1).to_i
|
44
48
|
limit = (@params[:limit] || 10).to_i
|
45
|
-
|
49
|
+
|
46
50
|
stocks = get
|
47
51
|
stocks = filter(stocks)
|
52
|
+
stocks = sort(stocks, @params[:sort]) if @params[:sort]
|
48
53
|
stocks = paginate(stocks, page, limit)
|
49
54
|
|
50
55
|
stocks || []
|
51
56
|
end
|
52
57
|
|
53
58
|
def price_all
|
54
|
-
get
|
59
|
+
stocks = get
|
60
|
+
|
61
|
+
stocks = sort(stocks, @params[:sort]) if @params[:sort]
|
62
|
+
|
63
|
+
stocks
|
55
64
|
end
|
56
65
|
|
57
66
|
private
|
@@ -84,16 +93,37 @@ module Aadyandana
|
|
84
93
|
end
|
85
94
|
|
86
95
|
def filter(stocks)
|
87
|
-
stocks = stocks.select { |stock| stock[
|
88
|
-
stocks = stocks.select { |stock| stock[
|
89
|
-
if @params[:company_name]
|
90
|
-
|
91
|
-
|
96
|
+
stocks = stocks.select { |stock| stock["identifier"] == @params[:identifier] } if @params[:identifier]
|
97
|
+
stocks = stocks.select { |stock| stock["symbol"] == @params[:symbol] } if @params[:symbol]
|
98
|
+
stocks = stocks.select { |stock| stock["meta"]["companyName"] == @params[:company_name] } if @params[:company_name]
|
99
|
+
stocks = stocks.select { |stock| stock["meta"]["industry"] == @params[:industry] } if @params[:industry]
|
100
|
+
stocks = stocks.select { |stock| stock["meta"]["isin"] == @params[:isin] } if @params[:isin]
|
101
|
+
|
102
|
+
stocks
|
103
|
+
end
|
104
|
+
|
105
|
+
def sort(stocks, sort)
|
106
|
+
field, type = sort.split(".")
|
107
|
+
|
108
|
+
stocks = stocks.sort_by do |stock|
|
109
|
+
value = stock[field]
|
110
|
+
|
111
|
+
if @datetime_attrs.include? field
|
112
|
+
value = DateTime.parse(value).to_time.to_i
|
113
|
+
value *= -1 if type == "desc"
|
114
|
+
elsif @string_attrs.include? field
|
115
|
+
value = stock["meta"][field] if @string_meta_attrs.include? field
|
116
|
+
value = value.present? ? value.downcase : "zzz"
|
117
|
+
else
|
118
|
+
value = value == "-" ? Float::INFINITY : value.to_f
|
119
|
+
value *= -1 if value != Float::INFINITY and type == "desc"
|
92
120
|
end
|
121
|
+
|
122
|
+
value
|
93
123
|
end
|
94
|
-
|
95
|
-
stocks = stocks.
|
96
|
-
|
124
|
+
|
125
|
+
stocks = stocks.reverse! if @string_attrs.include? field and type == "desc"
|
126
|
+
|
97
127
|
stocks
|
98
128
|
end
|
99
129
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aadyandana-latest_stock_price
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agus.adyandana
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.22.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.22.0
|
27
27
|
description: Fetches the latest stock prices from RapidAPI.
|
28
28
|
email:
|
29
29
|
- agus.adyandana@bigio.id
|