Class: DmtdVbmappData::Guide

Inherits:
Object
  • Object
show all
Defined in:
lib/dmtd_vbmapp_data/guide.rb

Overview

Provides for the retrieving of VB-MAPP Guide content from the VB-MAPP Data Server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Guide

Creates an accessor for the VB-MAPP Guide on the VB-MAPP Data Server

This method does not block, simply creates an accessor and returns

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :client (Client)

    A client instance



17
18
19
# File 'lib/dmtd_vbmapp_data/guide.rb', line 17

def initialize(opts)
  @client = opts.fetch(:client)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/dmtd_vbmapp_data/guide.rb', line 10

def client
  @client
end

Instance Method Details

#chaptersArray<GuideChapter>

Note:

The first call to this method with an expired cache will block until the cache is populated. All subsequent calls will load from the cache.

Note:

The cache is an in-memory cache (not on-disc). Thus, if the process is restarted, the cache will be dropped. Additionally this cache expires once a day at midnight UTC.

Returns The entire set of DmtdVbmappData::GuideChapter instances.

Returns:



29
30
31
32
33
34
35
# File 'lib/dmtd_vbmapp_data/guide.rb', line 29

def chapters
  @chapters = index.map.with_index do |chapter_json, chapter_num|
    GuideChapter.new(client: client, chapter_num: chapter_num, chapter_index_json: chapter_json)
  end if @chapters.nil?

  @chapters
end

#expire_cache(opts = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dmtd_vbmapp_data/guide.rb', line 37

def expire_cache(opts = {})
  if defined?(@@guide_cache) && !@@guide_cache.nil?
    today = DateTime.now.new_offset(0).to_date
    cache_day = @@guide_cache[:datestamp]

    if cache_day != today || !opts[:force].nil?
      @chapters = nil
      @@guide_cache = nil
    end
  end
end