Class: YahooFinance::CompanyProfile::CompanyProfilePage
- Inherits:
-
Object
- Object
- YahooFinance::CompanyProfile::CompanyProfilePage
- Defined in:
- lib/yahoo_finance/company_profile.rb
Instance Attribute Summary collapse
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Instance Method Summary collapse
- #doc ⇒ Object
- #fetch ⇒ Object
-
#initialize(symbol = nil) ⇒ CompanyProfilePage
constructor
A new instance of CompanyProfilePage.
- #value_for(key_stat) ⇒ Object
Constructor Details
#initialize(symbol = nil) ⇒ CompanyProfilePage
Returns a new instance of CompanyProfilePage.
20 21 22 |
# File 'lib/yahoo_finance/company_profile.rb', line 20 def initialize symbol=nil @symbol = symbol end |
Instance Attribute Details
#symbol ⇒ Object
Returns the value of attribute symbol.
18 19 20 |
# File 'lib/yahoo_finance/company_profile.rb', line 18 def symbol @symbol end |
Instance Method Details
#doc ⇒ Object
31 32 33 |
# File 'lib/yahoo_finance/company_profile.rb', line 31 def doc @doc end |
#fetch ⇒ Object
24 25 26 27 28 29 |
# File 'lib/yahoo_finance/company_profile.rb', line 24 def fetch url = "http://finance.yahoo.com/q/pr?s=#{@symbol}" open(url) do |stream| @doc = Nokogiri::HTML(stream) end end |
#value_for(key_stat) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/yahoo_finance/company_profile.rb', line 35 def value_for key_stat if key_stat == :website r = @doc.xpath("//td[contains(., \"#{YahooFinance::CompanyProfile::COMPANY_PROFILE_STATS[key_stat][0]}\")]") return r.xpath("./a[contains(., 'http:')]").text elsif key_stat == :company_name name = @doc.xpath('//td[@class="yfnc_modtitlew1"]//b')[0].text return name elsif CompanyProfile::key_events_available.include? key_stat begin value = @doc.xpath("//td[text() = \"#{YahooFinance::CompanyProfile::COMPANY_PROFILE_STATS[key_stat][0]}\"]")[0].parent.children[1].text return value rescue return nil end else raise StandardError::ArgumentError, "#{key_stat.to_s} not implemented" end end |