Class: Finviz::Quote

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

Overview

Single quote representation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ticker:, stats: nil) ⇒ Quote

Returns a new instance of Quote.



10
11
12
13
# File 'lib/finviz/quote.rb', line 10

def initialize(ticker:, stats: nil)
  @ticker = ticker
  @stats = ActiveSupport::HashWithIndifferentAccess.new(stats.to_h)
end

Instance Attribute Details

#statsObject (readonly)

Returns the value of attribute stats.



8
9
10
# File 'lib/finviz/quote.rb', line 8

def stats
  @stats
end

#tickerObject (readonly)

Returns the value of attribute ticker.



8
9
10
# File 'lib/finviz/quote.rb', line 8

def ticker
  @ticker
end

Instance Method Details

#chartObject



19
20
21
# File 'lib/finviz/quote.rb', line 19

def chart
  "https://charts2.finviz.com/chart.ashx?t=#{ticker}&ty=c&ta=1&p=d&s=l"
end

#pathObject



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

def path
  "https://finviz.com/quote.ashx?t=#{ticker}"
end

#to_hObject

grab all instance methods to the hash



24
25
26
27
28
# File 'lib/finviz/quote.rb', line 24

def to_h
  (self.class.instance_methods(false) - [__callee__]).each_with_object({}) do |method, acc|
    acc[method] = public_send method
  end
end