Class: SimplywallstSnowflake::Client
- Inherits:
-
Object
- Object
- SimplywallstSnowflake::Client
- Defined in:
- lib/simplywallst_snowflake.rb
Instance Attribute Summary collapse
-
#company_name ⇒ Object
readonly
Returns the value of attribute company_name.
-
#future ⇒ Object
readonly
Returns the value of attribute future.
-
#health ⇒ Object
readonly
Returns the value of attribute health.
-
#income ⇒ Object
readonly
Returns the value of attribute income.
-
#past ⇒ Object
readonly
Returns the value of attribute past.
-
#primary_exchange_symbol ⇒ Object
readonly
Returns the value of attribute primary_exchange_symbol.
-
#primary_ticker_symbol ⇒ Object
readonly
Returns the value of attribute primary_ticker_symbol.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#snowflake_colour ⇒ Object
readonly
Returns the value of attribute snowflake_colour.
-
#snowflake_scores ⇒ Object
readonly
Returns the value of attribute snowflake_scores.
-
#snowflake_tile_url ⇒ Object
readonly
Returns the value of attribute snowflake_tile_url.
-
#unique_symbol ⇒ Object
readonly
Returns the value of attribute unique_symbol.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#widget_url ⇒ Object
readonly
Returns the value of attribute widget_url.
Instance Method Summary collapse
-
#initialize(exchange, ticker) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(exchange, ticker) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/simplywallst_snowflake.rb', line 32 def initialize(exchange, ticker) raise "Error - Invalid exchange: '#{exchange}'" unless exchange =~ /\A[a-zA-Z0-9]+\z/ raise "Error - Invalid ticker: '#{ticker}'" unless ticker =~ /\A[a-zA-Z0-9]+\z/ @url = URI("https://simplywall.st/api/snowflake/#{exchange}:#{ticker}") begin response = Net::HTTP.get(@url) rescue => e raise "Error - Could not connect to SimplyWall.St: #{e.}" end if response.nil? || response.to_s.eql?('') || response.to_s.eql?('{}') raise 'Error - No response from SimplyWall.St' end @response = JSON.parse(response) unless @response['message'].nil? raise "Error - Could not retrieve snowflake: #{@response['message']}" end # Shortened company name @company_name = @response['companyName'] # Unique joined symbol for the company @unique_symbol = @response['uniqueSymbol'] # Primary exchange symbol @primary_exchange_symbol = @response['primaryExchangeSymbol'] # Primary ticker symbol @primary_ticker_symbol = @response['primaryTickerSymbol'] # Array of scores for each axis of the snowflake [ Value, Future, Past, Health, Income ] @snowflake_scores = @response['snowflakeScores'] # Scaled float used in colouring the snowflake, range 0.0 (healthy) to 1.0 (bad) @snowflake_colour = @response['snowflakeColour'] # A URL to the snowflake tile as a widget to be used in an iframe @widget_url = @response['widgetURL'] # A URL to a rendered tile of the companies snowflake @snowflake_tile_url = @response['snowflakeTileURL'] # Value - value based on future cash flows and its price relative to the stock market @value = @snowflake_scores[0] # Future Performance - expected performance in the next 3 years @future = @snowflake_scores[1] # Past Performance - historical performance over the past 5 years @past = @snowflake_scores[2] # Health - financial health and the level of debt @health = @snowflake_scores[3] # Income - the current dividend yield, its volatility and sustainability @income = @snowflake_scores[4] end |
Instance Attribute Details
#company_name ⇒ Object (readonly)
Returns the value of attribute company_name.
17 18 19 |
# File 'lib/simplywallst_snowflake.rb', line 17 def company_name @company_name end |
#future ⇒ Object (readonly)
Returns the value of attribute future.
27 28 29 |
# File 'lib/simplywallst_snowflake.rb', line 27 def future @future end |
#health ⇒ Object (readonly)
Returns the value of attribute health.
29 30 31 |
# File 'lib/simplywallst_snowflake.rb', line 29 def health @health end |
#income ⇒ Object (readonly)
Returns the value of attribute income.
30 31 32 |
# File 'lib/simplywallst_snowflake.rb', line 30 def income @income end |
#past ⇒ Object (readonly)
Returns the value of attribute past.
28 29 30 |
# File 'lib/simplywallst_snowflake.rb', line 28 def past @past end |
#primary_exchange_symbol ⇒ Object (readonly)
Returns the value of attribute primary_exchange_symbol.
19 20 21 |
# File 'lib/simplywallst_snowflake.rb', line 19 def primary_exchange_symbol @primary_exchange_symbol end |
#primary_ticker_symbol ⇒ Object (readonly)
Returns the value of attribute primary_ticker_symbol.
20 21 22 |
# File 'lib/simplywallst_snowflake.rb', line 20 def primary_ticker_symbol @primary_ticker_symbol end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
14 15 16 |
# File 'lib/simplywallst_snowflake.rb', line 14 def response @response end |
#snowflake_colour ⇒ Object (readonly)
Returns the value of attribute snowflake_colour.
22 23 24 |
# File 'lib/simplywallst_snowflake.rb', line 22 def snowflake_colour @snowflake_colour end |
#snowflake_scores ⇒ Object (readonly)
Returns the value of attribute snowflake_scores.
21 22 23 |
# File 'lib/simplywallst_snowflake.rb', line 21 def snowflake_scores @snowflake_scores end |
#snowflake_tile_url ⇒ Object (readonly)
Returns the value of attribute snowflake_tile_url.
24 25 26 |
# File 'lib/simplywallst_snowflake.rb', line 24 def snowflake_tile_url @snowflake_tile_url end |
#unique_symbol ⇒ Object (readonly)
Returns the value of attribute unique_symbol.
18 19 20 |
# File 'lib/simplywallst_snowflake.rb', line 18 def unique_symbol @unique_symbol end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
15 16 17 |
# File 'lib/simplywallst_snowflake.rb', line 15 def url @url end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
26 27 28 |
# File 'lib/simplywallst_snowflake.rb', line 26 def value @value end |
#widget_url ⇒ Object (readonly)
Returns the value of attribute widget_url.
23 24 25 |
# File 'lib/simplywallst_snowflake.rb', line 23 def @widget_url end |