Class: Dmm::Price

Inherits:
Base
  • Object
show all
Defined in:
lib/dmm/price.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attr_reader, #initialize

Constructor Details

This class inherits a constructor from Dmm::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/dmm/price.rb', line 30

def method_missing(method, *args)
  if method.to_s =~ /^price_(\w+)$/
    array = deliveries.select{ |hash| hash[:type] == $1 }
    array.first[:price].to_i unless array.empty?
  else
    super
  end
end

Instance Attribute Details

#priceObject (readonly)

Returns the value of attribute price.



5
6
7
# File 'lib/dmm/price.rb', line 5

def price
  @price
end

Instance Method Details

#deliveriesArray<Hash>

Returns an array of hashes with a type of delivery as key and price as value

Returns:



17
18
19
20
# File 'lib/dmm/price.rb', line 17

def deliveries
  return [] unless @attrs[:deliveries]
  @attrs[:deliveries][:delivery]
end

#delivery_typesArray

Returns an array containing type of delivery

Returns:

  • (Array)


25
26
27
28
# File 'lib/dmm/price.rb', line 25

def delivery_types
  @delivery_types ||= deliveries.map { |price| price[:type] }
  @delivery_types
end

#min_priceInteger

Returns minimum price of item

Returns:

  • (Integer)


10
11
12
# File 'lib/dmm/price.rb', line 10

def min_price
  @attrs[:price].to_i
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


40
# File 'lib/dmm/price.rb', line 40

def respond_to?(method, include_private = false); method.to_s =~ /^price_(\w+)$/ || super; end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


39
# File 'lib/dmm/price.rb', line 39

def respond_to_missing?(method, include_private = false); method.to_s =~ /^price_(\w+)$/ || super; end