Class: SchwabRb::DataObjects::MarketHours::SessionPeriod

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/data_objects/market_hours.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ SessionPeriod

Returns a new instance of SessionPeriod.



242
243
244
245
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 242

def initialize(data)
  @start_time = data["start"]
  @end_time = data["end"]
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



240
241
242
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 240

def end_time
  @end_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



240
241
242
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 240

def start_time
  @start_time
end

Instance Method Details

#active_now?Boolean

Returns:

  • (Boolean)


272
273
274
275
276
277
278
279
280
281
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 272

def active_now?
  return false unless @start_time && @end_time

  now = Time.now
  start_obj = start_time_object
  end_obj = end_time_object
  return false unless start_obj && end_obj

  now >= start_obj && now <= end_obj
end

#duration_minutesObject



262
263
264
265
266
267
268
269
270
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 262

def duration_minutes
  return nil unless @start_time && @end_time

  start_obj = start_time_object
  end_obj = end_time_object
  return nil unless start_obj && end_obj

  ((end_obj - start_obj) / 60).to_i
end

#end_time_objectObject



258
259
260
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 258

def end_time_object
  Time.parse(@end_time) if @end_time
end

#start_time_objectObject



254
255
256
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 254

def start_time_object
  Time.parse(@start_time) if @start_time
end

#to_hObject



247
248
249
250
251
252
# File 'lib/schwab_rb/data_objects/market_hours.rb', line 247

def to_h
  {
    "start" => @start_time,
    "end" => @end_time
  }
end