Class: SimplywallstSnowflake::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/simplywallst_snowflake.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.message}"
  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_nameObject (readonly)

Returns the value of attribute company_name.



17
18
19
# File 'lib/simplywallst_snowflake.rb', line 17

def company_name
  @company_name
end

#futureObject (readonly)

Returns the value of attribute future.



27
28
29
# File 'lib/simplywallst_snowflake.rb', line 27

def future
  @future
end

#healthObject (readonly)

Returns the value of attribute health.



29
30
31
# File 'lib/simplywallst_snowflake.rb', line 29

def health
  @health
end

#incomeObject (readonly)

Returns the value of attribute income.



30
31
32
# File 'lib/simplywallst_snowflake.rb', line 30

def income
  @income
end

#pastObject (readonly)

Returns the value of attribute past.



28
29
30
# File 'lib/simplywallst_snowflake.rb', line 28

def past
  @past
end

#primary_exchange_symbolObject (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_symbolObject (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

#responseObject (readonly)

Returns the value of attribute response.



14
15
16
# File 'lib/simplywallst_snowflake.rb', line 14

def response
  @response
end

#snowflake_colourObject (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_scoresObject (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_urlObject (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_symbolObject (readonly)

Returns the value of attribute unique_symbol.



18
19
20
# File 'lib/simplywallst_snowflake.rb', line 18

def unique_symbol
  @unique_symbol
end

#urlObject (readonly)

Returns the value of attribute url.



15
16
17
# File 'lib/simplywallst_snowflake.rb', line 15

def url
  @url
end

#valueObject (readonly)

Returns the value of attribute value.



26
27
28
# File 'lib/simplywallst_snowflake.rb', line 26

def value
  @value
end

#widget_urlObject (readonly)

Returns the value of attribute widget_url.



23
24
25
# File 'lib/simplywallst_snowflake.rb', line 23

def widget_url
  @widget_url
end