Class: BorrowDirect::PickupLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/borrow_direct/pickup_location.rb

Overview

Returned from FindItem::Response.pickup_locations , contains a #code and a #description . #to_a returns a handy duple suitable for passing to Rails options_for_select

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bd_hash) ⇒ PickupLocation

Returns a new instance of PickupLocation.



7
8
9
10
11
12
13
# File 'lib/borrow_direct/pickup_location.rb', line 7

def initialize(bd_hash)
  if bd_hash["PickupLocationCode"].empty? || bd_hash["PickupLocationDescription"].empty?
    raise ArgumentError, "PickupLocation requires a hash with PickupLocationCode and PickupLocationDescription, not `#{bd_hash}`"
  end

  @response_hash = bd_hash
end

Instance Attribute Details

#response_hashObject (readonly)

Returns the value of attribute response_hash.



6
7
8
# File 'lib/borrow_direct/pickup_location.rb', line 6

def response_hash
  @response_hash
end

Instance Method Details

#codeObject



15
16
17
# File 'lib/borrow_direct/pickup_location.rb', line 15

def code
  @response_hash["PickupLocationCode"]
end

#descriptionObject



19
20
21
# File 'lib/borrow_direct/pickup_location.rb', line 19

def description
  @response_hash["PickupLocationDescription"]
end

#to_aObject

Handy for passing to Rails options_for_select



28
29
30
# File 'lib/borrow_direct/pickup_location.rb', line 28

def to_a
  [self.description, self.code]
end

#to_hObject



23
24
25
# File 'lib/borrow_direct/pickup_location.rb', line 23

def to_h
  self.response_hash
end