Class: Shelbytv::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/shelbytv/channel.rb

Constant Summary collapse

FIELDS =
[ :name, :user_id ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shelbytv, json) ⇒ Channel

Returns a new instance of Channel.



7
8
9
# File 'lib/shelbytv/channel.rb', line 7

def initialize(shelbytv, json)
  @shelbytv, @json = shelbytv, json
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/shelbytv/channel.rb', line 33

def method_missing(method_name, *args)
  if FIELDS.include?(method_name)
    @json[method_name.to_s]
  else
    super
  end
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



5
6
7
# File 'lib/shelbytv/channel.rb', line 5

def json
  @json
end

Instance Method Details

#broadcasts(options = {}) ⇒ Object



15
16
17
18
19
# File 'lib/shelbytv/channel.rb', line 15

def broadcasts(options={})
  @shelbytv.get("channels/#{id}/broadcasts.json", options).map do |item|
    Shelbytv::Broadcast.new(@shelbytv, item)
  end
end

#created_atObject



21
22
23
# File 'lib/shelbytv/channel.rb', line 21

def created_at
  Time.parse(@json['created_at'])
end

#idObject



11
12
13
# File 'lib/shelbytv/channel.rb', line 11

def id
  @json['_id']
end

#is_publicObject



25
26
27
# File 'lib/shelbytv/channel.rb', line 25

def is_public
  @json['public']
end

#is_public?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/shelbytv/channel.rb', line 29

def is_public?
  is_public
end

#updated_atObject



41
42
43
# File 'lib/shelbytv/channel.rb', line 41

def updated_at
  Time.parse(@json['created_at'])
end

#userObject



45
46
47
# File 'lib/shelbytv/channel.rb', line 45

def user
  @shelbytv.users.find(user_id)
end