Class: Alphavantage::Sector
- Inherits:
-
Object
- Object
- Alphavantage::Sector
- Includes:
- HelperFunctions
- Defined in:
- lib/Sector.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(key:, verbose: false) ⇒ Sector
constructor
A new instance of Sector.
Methods included from HelperFunctions
#check_argument, #check_datatype, #method_missing, #open_struct, #recreate_metadata_key, #return_client, #return_int_val, #return_matype, #return_series, #return_value, #which_series
Constructor Details
#initialize(key:, verbose: false) ⇒ Sector
Returns a new instance of Sector.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/Sector.rb', line 5 def initialize key:, verbose: false check_argument([true, false], verbose, "verbose") @client = return_client(key, verbose) @output = @client.request("function=SECTOR") = @output.dig("Meta Data") || {} .each do |k, val| key_sym = k.downcase.gsub(/[0-9.]/, "").lstrip.gsub(" ", "_").to_sym define_singleton_method(key_sym) do return val end end @output.each do |k, val| next if k == "Meta Data" k = k.split(":")[1].lstrip k = k.split(" ") if k[0].to_i != 0 k[0] = k[0].to_i.humanize end k.delete_if{|ka| ka.include?("(")} k = k.join("_") key_sym = k.downcase.gsub("-", "_").to_sym define_singleton_method(key_sym) do return val end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class HelperFunctions
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
32 33 34 |
# File 'lib/Sector.rb', line 32 def output @output end |