Module: Yfinrb::Quote
Class Method Summary collapse
-
.included(base) ⇒ Object
built-in Ruby hook for modules.
Instance Method Summary collapse
- #calendar ⇒ Object
-
#info ⇒ Object
(self).
- #initialize_quote ⇒ Object
- #recommendations ⇒ Object (also: #recommendation_summary, #recommendations_summary)
- #sustainability ⇒ Object
- #upgrades_downgrades ⇒ Object
- #valid_modules ⇒ Object
Class Method Details
.included(base) ⇒ Object
built-in Ruby hook for modules
7 8 9 10 11 12 13 14 15 |
# File 'lib/yfinrb/quote.rb', line 7 def self.included(base) # built-in Ruby hook for modules base.class_eval do original_method = instance_method(:initialize) define_method(:initialize) do |*args, &block| original_method.bind(self).call(*args, &block) initialize_quote # (your module code here) end end end |
Instance Method Details
#calendar ⇒ Object
93 94 95 96 |
# File 'lib/yfinrb/quote.rb', line 93 def calendar self._fetch_calendar() if @calendar.nil? return @calendar end |
#info ⇒ Object
(self)
30 31 32 33 34 35 36 |
# File 'lib/yfinrb/quote.rb', line 30 def info #(self) if @info.nil? _fetch_info() #(@proxy) _fetch_complementary() #(@proxy) end return @info end |
#initialize_quote ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yfinrb/quote.rb', line 17 def initialize_quote @info = nil @retired_info = nil @sustainability = nil @recommendations = nil @upgrades_downgrades = nil @calendar = nil @already_scraped = false @already_fetched = false @already_fetched_complementary = false end |
#recommendations ⇒ Object Also known as: recommendation_summary, recommendations_summary
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/yfinrb/quote.rb', line 43 def recommendations Polars::Config.set_tbl_rows(-1) if @recommendations.nil? result = _fetch(['recommendationTrend']).parsed_response # Rails.logger.info { "#{__FILE__}:#{__LINE__} result = #{result.inspect}" } # if result.nil? # @recommendations = Yfinrb::Utils.empty_df() #Polars::DataFrame() # else begin data = result["quoteSummary"]["result"][0]["recommendationTrend"]["trend"] rescue KeyError, IndexError => e raise YfinDataException(f"Failed to parse json response from Yahoo Finance: #{e.result}") end @recommendations = Polars::DataFrame.new(data) # end end return @recommendations end |
#sustainability ⇒ Object
38 39 40 41 |
# File 'lib/yfinrb/quote.rb', line 38 def sustainability raise YFNotImplementedError.new('sustainability') if @sustainability.nil? return @sustainability end |
#upgrades_downgrades ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/yfinrb/quote.rb', line 66 def upgrades_downgrades Polars::Config.set_tbl_rows(-1) if @upgrades_downgrades.nil? result = _fetch(['upgradeDowngradeHistory']).parsed_response # Rails.logger.info { "#{__FILE__}:#{__LINE__} result = #{result.inspect}" } # if result.nil? # @upgrades_downgrades = Yfinrb::Utils.empty_df() #Polars::DataFrame() # else begin data = result["quoteSummary"]["result"][0]["upgradeDowngradeHistory"]["history"] raise YfinDataException("No upgrade/downgrade history found for #{ticker.symbol}") if (data).length.zero? df = Polars::DataFrame.new(data) df.rename({"epochGradeDate" => "GradeDate", 'firm' => 'Firm', 'toGrade' => 'ToGrade', 'fromGrade' => 'FromGrade', 'action' => 'Action'}) # df.set_index('GradeDate', inplace=true) # df.index = pd.to_datetime(df.index, unit='s') @upgrades_downgrades = df rescue KeyError, IndexError => e raise YfinDataException("Failed to parse json response from Yahoo Finance: #{e.result}") end # end end return @upgrades_downgrades end |
#valid_modules ⇒ Object
98 99 100 |
# File 'lib/yfinrb/quote.rb', line 98 def valid_modules() return QUOTE_SUMMARY_VALID_MODULES end |