Class: Stockery::Quote

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQuote

Returns a new instance of Quote.



5
6
7
# File 'lib/stockery/quote.rb', line 5

def initialize
  self.source = Stockery::GOOGLE # default
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/stockery/quote.rb', line 3

def source
  @source
end

Instance Method Details

#get_status(symbol) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/stockery/quote.rb', line 9

def get_status(symbol)
  result = case source.upcase
    when Stockery::GOOGLE then
      fetch_goog(symbol)
    when Stockery::YAHOO then
      fetch_yahoo(symbol)
    else
      abort "No valid source specified. The following source are available: \"GOOGLE\", \"YAHOO\""
    end
 
  unless result.empty?
    result[:timestamp] = Time.now.getutc
      
    result
  else
    nil
  end
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/stockery/quote.rb', line 28

def print(stockery_data)
  printed = ""

  unless stockery_data.nil? || stockery_data.empty?
    printed += "#{stockery_data[:name]} on #{stockery_data[:market]} @ #{stockery_data[:timestamp]}\n"
    # printed += " *** MARKET CLOSED ***\n" if Time.now.strftime("%H:%M") > "16:00"
    
    printed_pr = "#{stockery_data[:price]} #{stockery_data[:change_points]} (#{stockery_data[:change_procent]}%)"
    printed += stockery_data[:change_points].to_f < 0 ? printed_pr.red : printed_pr.green
  else
    printed += "Stock data invalid or empty"
  end

  printed
end