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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce1e4f1a2336e5461485a5dc8c2a162b26690555f16cdc4db5d6228034874715
4
- data.tar.gz: 98d5d5bcd147ea1189f01cf5da527ff18fb7c4179565d44e890492226ca49740
3
+ metadata.gz: fd38ba3dabb637a579797d9dbfa635bf84750a6e39ffbe98810d3665098b94ba
4
+ data.tar.gz: '0896beedbf3f06f69687b7b8e76f652f287cf776859911f61f6babe1322fc09c'
5
5
  SHA512:
6
- metadata.gz: 267a375d5fdf19fbc26b2b7461199ae364e2459951d9893448630e47436907293e8edcf89b4d9b16e6a17bc026382c451a1c676375fbbc6b0ec024af93b84cdf
7
- data.tar.gz: 3e23f9bec687b2c401670b2fcf8c9be26e63f859d29ac6769c7ebc33a6aaaded490958f74ee0c8e94ce64371f43fdf2d0f99cbe73efd75e5e30831be8096b691
6
+ metadata.gz: 82ee3b246f777fb1e677476e2d3c6306986745a131038117a1a98c1c5c729ff1b4fcab5922be281a5e0e71d39102b1c9cefb7be8ef240f3398c8a8460a778ea7
7
+ data.tar.gz: 75b8d8e31b7863237af447952fa92661b8883bf70de55452999d4d21c0018608ba1371f3db063d83f2c006b46abe4b5c7cc0bdb60fded4ba79a110b40dc451d0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2024-10-05
3
+ ## [1.1.0] - 2024-10-05
4
4
 
5
5
  - Initial release
6
+
7
+ ## [2.0.0] - 2024-10-06
8
+
9
+ - Add filter
10
+ - Add sort
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aadyandana
4
4
  module LatestStockPrice
5
- VERSION = "1.1.0"
5
+ VERSION = "2.0.0"
6
6
  end
7
7
  end
@@ -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[:identifier] == @params[:identifier] } if @params[:identifier]
88
- stocks = stocks.select { |stock| stock[:symbol] == @params[:symbol] } if @params[:symbol]
89
- if @params[:company_name]
90
- stocks = stocks.select do |stock|
91
- stock[:meta][:companyName] == @params[:company_name]
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
- stocks = stocks.select { |stock| stock[:meta][:industry] == @params[:industry] } if @params[:industry]
95
- stocks = stocks.select { |stock| stock[:meta][:isin] == @params[:isin] } if @params[:isin]
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: 1.1.0
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-05 00:00:00.000000000 Z
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: '0'
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: '0'
26
+ version: 0.22.0
27
27
  description: Fetches the latest stock prices from RapidAPI.
28
28
  email:
29
29
  - agus.adyandana@bigio.id