Class: RedfinAsDataframe::National
- Inherits:
-
Object
- Object
- RedfinAsDataframe::National
- Includes:
- HTTParty
- Defined in:
- lib/redfin_as_dataframe/national.rb
Instance Attribute Summary collapse
-
#ary ⇒ Object
readonly
Returns the value of attribute ary.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #fetch(start: nil, fin: nil) ⇒ Object
-
#initialize(series = nil, options = {}) ⇒ National
constructor
A new instance of National.
Constructor Details
#initialize(series = nil, options = {}) ⇒ National
Returns a new instance of National.
16 17 18 |
# File 'lib/redfin_as_dataframe/national.rb', line 16 def initialize(series = nil, ={}) @tag = series end |
Instance Attribute Details
#ary ⇒ Object (readonly)
Returns the value of attribute ary.
14 15 16 |
# File 'lib/redfin_as_dataframe/national.rb', line 14 def ary @ary end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
14 15 16 |
# File 'lib/redfin_as_dataframe/national.rb', line 14 def tag @tag end |
Instance Method Details
#fetch(start: nil, fin: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/redfin_as_dataframe/national.rb', line 20 def fetch(start: nil, fin: nil) dat = _fetch_data.dup hsh = dat.map!{|r| r.to_hash } keys = hsh.first.keys vals = hsh.map(&:values).transpose df = {}; (0..(keys.length-1)).to_a.each{|i| df[keys[i]] = vals[i]} df = Polars::DataFrame.new(df).drop(['period_duration', 'region_type', 'region_type_id','table_id','is_seasonally_adjusted','region','city','state','state_code', 'parent_metro_region', 'parent_metro_region_metro_code']) df = df.filter(Polars.col('period_begin') >= (start.is_a?(Date) ? start : Date.parse(start.to_s))) unless start.nil? df = df.filter(Polars.col('period_end') <= (fin.is_a?(Date) ? fin : Date.parse(fin.to_s))) unless fin.nil? s = Polars::Series.new('Timestamps', df['period_begin'].to_a) df = df.insert_column(0,s) df = (tag.nil? ? df : df.drop(df.columns - ['Timestamps', tag])).sort('Timestamps') end |