Class: Tangerine::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tangerine/backlot/base.rb

Direct Known Subclasses

Channel, ChannelSet, Player, Video

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



3
4
5
6
7
8
9
10
11
12
# File 'lib/tangerine/backlot/base.rb', line 3

def initialize(options={})
  options.delete('content_type')
  options.each do |k,v|
    # TODO: Look into using Crack gem for reliably undercoring these
    attr = k.to_s.underscore
    method = :"#{attr}="

    self.send(method, v) if self.class.method_defined?(method)
  end
end

Class Method Details

.allObject



29
30
31
32
# File 'lib/tangerine/backlot/base.rb', line 29

def self.all
  items = prepare_items @finder.call
  items.collect { |item| self.new(item) }
end

.find(embed_code) ⇒ Object



23
24
25
26
27
# File 'lib/tangerine/backlot/base.rb', line 23

def self.find(embed_code)
  results = prepare_items @finder.call(embed_code)
  found_item = results.select { |item| item['embedCode'] == embed_code }.first
  self.new(found_item)
end

.finder(&block) ⇒ Object



19
20
21
# File 'lib/tangerine/backlot/base.rb', line 19

def self.finder(&block)
  @finder = block
end

.prepare_items(items) ⇒ Object



14
15
16
17
# File 'lib/tangerine/backlot/base.rb', line 14

def self.prepare_items(items)
  # Yes, we are fully aware that type-checking sucks. Move along now, nothing to see here.
  items.is_a?(Array) ? items : [items]
end