Class: Uktt::Commodity
- Inherits:
-
Object
- Object
- Uktt::Commodity
- Defined in:
- lib/uktt/commodity.rb
Overview
A Commodity object for dealing with an API resource
Instance Attribute Summary collapse
-
#commodity_id ⇒ Object
Returns the value of attribute commodity_id.
-
#config ⇒ Object
Returns the value of attribute config.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #changes ⇒ Object
- #find(id) ⇒ Object
- #find_in(arr) ⇒ Object
-
#initialize(opts = {}) ⇒ Commodity
constructor
A new instance of Commodity.
- #retrieve ⇒ Object
Constructor Details
Instance Attribute Details
#commodity_id ⇒ Object
Returns the value of attribute commodity_id.
4 5 6 |
# File 'lib/uktt/commodity.rb', line 4 def commodity_id @commodity_id end |
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/uktt/commodity.rb', line 4 def config @config end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/uktt/commodity.rb', line 4 def response @response end |
Instance Method Details
#changes ⇒ Object
19 20 21 22 23 |
# File 'lib/uktt/commodity.rb', line 19 def changes return '@commodity_id cannot be nil' if @commodity_id.nil? fetch "#{COMMODITY}/#{@commodity_id}/changes.json" end |
#find(id) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/uktt/commodity.rb', line 32 def find(id) return '@response is nil, run #retrieve first' unless @response response = @response.included.select do |obj| obj.id === id || obj.type === id end response.length == 1 ? response.first : response end |
#find_in(arr) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/uktt/commodity.rb', line 41 def find_in(arr) return '@response is nil, run #retrieve first' unless @response response = @response.included.select do |obj| arr.include?(obj.id) end response.length == 1 ? response.first : response end |
#retrieve ⇒ Object
13 14 15 16 17 |
# File 'lib/uktt/commodity.rb', line 13 def retrieve return '@commodity_id cannot be nil' if @commodity_id.nil? fetch "#{COMMODITY}/#{@commodity_id}.json" end |