Class: NetworkExecutive::Program

Inherits:
Object
  • Object
show all
Defined in:
app/models/network_executive/program.rb

Direct Known Subclasses

OffAir

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_name(name) ⇒ Object

TODO: Is this the right place for this?



95
96
97
98
99
# File 'app/models/network_executive/program.rb', line 95

def find_by_name( name )
  Network.programming.find do |p|
    p.name == name
  end
end

.inherited(klass) ⇒ Object



90
91
92
# File 'app/models/network_executive/program.rb', line 90

def inherited( klass )
  Network.programming << klass.new
end

Instance Method Details

#display_nameObject



12
13
14
# File 'app/models/network_executive/program.rb', line 12

def display_name
  name.titleize
end

#nameObject



8
9
10
# File 'app/models/network_executive/program.rb', line 8

def name
  self.class.name.demodulize.underscore
end

#onloadObject

A Hash containing data to pass to the embedded page via postMessage once the IFRAME has indicated that it has loaded.



32
33
34
# File 'app/models/network_executive/program.rb', line 32

def onload
  {}
end

#onshowObject

A Hash containing data to pass to the embedded page via postMessage whenever a program is initially shown



44
45
46
47
48
49
50
51
# File 'app/models/network_executive/program.rb', line 44

def onshow
  {
    name:    name,
    url:     url,
    onLoad:  onload,
    refresh: refresh
  }
end

#onupdateObject

A Hash containing data to pass to the embedded page via postMessage whenever a program update is issued.



38
39
40
# File 'app/models/network_executive/program.rb', line 38

def onupdate
  {}
end

#play(&block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/network_executive/program.rb', line 53

def play( &block )
  Rails.logger.info %Q[Started playing "#{display_name}" at #{Time.now} (refresh: #{refresh})]

  defer = EM::DefaultDeferrable.new

  defer.callback( &block )

  EM.defer do
    payload = onshow.merge( event:'show:program' )
    json    = MultiJson.encode( payload )

    defer.succeed json
  end

  defer
end

#refreshObject

Will the embedded page be responsible for keeping the content fresh?

  • ‘:auto` - The page will be reloaded the page every minute.

  • ‘FALSE` - The page will not be reloaded

Defaults to ‘:auto`



26
27
28
# File 'app/models/network_executive/program.rb', line 26

def refresh
  :auto
end

#update(&block) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/network_executive/program.rb', line 70

def update( &block )
  return play( &block ) if refresh == :auto

  Rails.logger.info %Q[Started updating "#{display_name}" at #{Time.now}]

  defer = EM::DefaultDeferrable.new

  defer.callback( &block )

  EM.defer do
    payload = onupdate.merge( event:'update:program' )
    json    = MultiJson.encode( payload )

    defer.succeed json
  end

  defer
end

#urlObject



16
17
18
# File 'app/models/network_executive/program.rb', line 16

def url
  ''
end