Class: Dmm::Price
Instance Attribute Summary collapse
-
#price ⇒ Object
readonly
Returns the value of attribute price.
Instance Method Summary collapse
-
#deliveries ⇒ Array<Hash>
Returns an array of hashes with a type of delivery as key and price as value.
-
#delivery_types ⇒ Array
Returns an array containing type of delivery.
- #method_missing(method, *args) ⇒ Object
-
#min_price ⇒ Integer
Returns minimum price of item.
- #respond_to?(method, include_private = false) ⇒ Boolean
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Methods inherited from Base
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
#price ⇒ Object (readonly)
Returns the value of attribute price.
5 6 7 |
# File 'lib/dmm/price.rb', line 5 def price @price end |
Instance Method Details
#deliveries ⇒ Array<Hash>
Returns an array of hashes with a type of delivery as key and price as value
17 18 19 20 |
# File 'lib/dmm/price.rb', line 17 def deliveries return [] unless @attrs[:deliveries] @attrs[:deliveries][:delivery] end |
#delivery_types ⇒ Array
Returns an array containing type of delivery
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_price ⇒ Integer
Returns minimum price of item
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
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
39 |
# File 'lib/dmm/price.rb', line 39 def respond_to_missing?(method, include_private = false); method.to_s =~ /^price_(\w+)$/ || super; end |