Class: Emporium::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/emporium/product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ Product

Returns a new instance of Product.



6
7
8
9
# File 'lib/emporium/product.rb', line 6

def initialize(code)
  @code = Emporium::Code.new(code)
  raise "invalid code" unless @code.valid?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



28
29
30
31
32
33
34
# File 'lib/emporium/product.rb', line 28

def method_missing(name, *args)
  if self.instance_variables.include? :"@#{name}"
    self.instance_variable_get("@#{name}")
  else
    super
  end
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/emporium/product.rb', line 3

def code
  @code
end

#serviceObject

Returns the value of attribute service.



4
5
6
# File 'lib/emporium/product.rb', line 4

def service
  @service
end

Instance Method Details

#fetch!Object



11
12
13
14
# File 'lib/emporium/product.rb', line 11

def fetch!
  @service.response
  create @service.response
end