module Captive::Base::ClassMethods

Public Instance Methods

from_blob(blob:) click to toggle source
# File lib/captive/base.rb, line 14
def from_blob(blob:)
  new(cue_list: parse(blob: blob))
end
from_file(filename:) click to toggle source
# File lib/captive/base.rb, line 6
def from_file(filename:)
  file = File.new(filename, 'r:bom|utf-8')
  blob = file.read
  from_blob(blob: blob)
ensure
  file&.close
end
from_json(json:, mapping: {}) click to toggle source
# File lib/captive/base.rb, line 18
def from_json(json:, mapping: {})
  json = JSON.parse(json) if json.is_a?(String)
  cues = json['cues'] || json[:cues]
  raise InvalidJsonInput unless cues.is_a?(Array)

  cues.map! { |cue_json| Cue.from_json(json: cue_json, mapping: mapping) }
  new(cue_list: cues)
end