Class: SchwabRb::DataObjects::MarketHours::SessionPeriod
- Inherits:
-
Object
- Object
- SchwabRb::DataObjects::MarketHours::SessionPeriod
- Defined in:
- lib/schwab_rb/data_objects/market_hours.rb
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #active_now? ⇒ Boolean
- #duration_minutes ⇒ Object
- #end_time_object ⇒ Object
-
#initialize(data) ⇒ SessionPeriod
constructor
A new instance of SessionPeriod.
- #start_time_object ⇒ Object
- #to_h ⇒ Object
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_time ⇒ Object (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_time ⇒ Object (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
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_minutes ⇒ Object
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_object ⇒ Object
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_object ⇒ Object
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_h ⇒ Object
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 |