Class: MyShows::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/myshows/item.rb

Direct Known Subclasses

Episode, Show

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data) ⇒ Item

Returns a new instance of Item.



5
6
7
8
9
10
# File 'lib/myshows/item.rb', line 5

def initialize(id, data)
  @api = MyShows::API.instance

  @id = id
  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/myshows/item.rb', line 12

def method_missing(name, *args)
  return super(name, *args) if args.count > 0

  # convert to camel case
  cc_name = name.to_s.gsub(/_[a-z]/) {|a| a.upcase }.gsub '_', ''

  @data[cc_name] or super(name)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/myshows/item.rb', line 3

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/myshows/item.rb', line 21

def ==(other)
  self.class == other.class && self.id == other.id
end