Class: Alma::BibItem

Inherits:
Object
  • Object
show all
Extended by:
ApiDefaults, Forwardable
Defined in:
lib/alma/bib_item.rb

Constant Summary collapse

PERMITTED_ARGS =
[
  :limit, :offset, :expand, :user_id, :current_library,
  :current_location, :q, :order_by, :direction
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiDefaults

apikey, bibs_base_path, configuration_base_path, headers, items_base_path, region, timeout, users_base_path

Constructor Details

#initialize(item) ⇒ BibItem

Returns a new instance of BibItem.



36
37
38
# File 'lib/alma/bib_item.rb', line 36

def initialize(item)
  @item = item
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



9
10
11
# File 'lib/alma/bib_item.rb', line 9

def item
  @item
end

Class Method Details

.find(mms_id, options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/alma/bib_item.rb', line 17

def self.find(mms_id, options = {})
  holding_id = options.delete(:holding_id) || "ALL"
  options.select! { |k, _| PERMITTED_ARGS.include? k }
  url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items"
  response = HTTParty.get(url, headers: headers, query: options, timeout: timeout)
  BibItemSet.new(response, options.merge({ mms_id: mms_id, holding_id: holding_id }))
end

.find_by_barcode(barcode) ⇒ Object



25
26
27
28
# File 'lib/alma/bib_item.rb', line 25

def self.find_by_barcode(barcode)
  response = HTTParty.get(items_base_path, headers: headers, query: { item_barcode: barcode }, timeout: timeout, follow_redirects: true)
  new(response)
end

.scan(mms_id:, holding_id:, item_pid:, options: {}) ⇒ Object



30
31
32
33
34
# File 'lib/alma/bib_item.rb', line 30

def self.scan(mms_id:, holding_id:, item_pid:, options: {})
  url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items/#{item_pid}"
  response = HTTParty.post(url, headers: headers, query: options)
  new(response)
end

Instance Method Details

#alt_call_numberObject



120
121
122
# File 'lib/alma/bib_item.rb', line 120

def alt_call_number
  item_data.fetch("alternative_call_number", "")
end

#base_statusObject



136
137
138
# File 'lib/alma/bib_item.rb', line 136

def base_status
  item_data.dig("base_status", "value") || ""
end

#call_numberObject



108
109
110
111
112
113
114
# File 'lib/alma/bib_item.rb', line 108

def call_number
  if has_temp_call_number?
    holding_data.fetch("temp_call_number")
  else
    holding_data.fetch("call_number", "")
  end
end

#circulation_policyObject



144
145
146
# File 'lib/alma/bib_item.rb', line 144

def circulation_policy
  item_data.dig("policy", "desc") || ""
end

#descriptionObject



152
153
154
# File 'lib/alma/bib_item.rb', line 152

def description
  item_data.fetch("description", "")
end

#has_alt_call_number?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/alma/bib_item.rb', line 116

def has_alt_call_number?
  !alt_call_number.empty?
end

#has_process_type?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/alma/bib_item.rb', line 124

def has_process_type?
  !process_type.empty?
end

#has_temp_call_number?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/alma/bib_item.rb', line 104

def has_temp_call_number?
  !temp_call_number.empty?
end

#holding_dataObject



40
41
42
# File 'lib/alma/bib_item.rb', line 40

def holding_data
  @item.fetch("holding_data", {})
end

#holding_libraryObject



68
69
70
# File 'lib/alma/bib_item.rb', line 68

def holding_library
  item_data.dig("library", "value")
end

#holding_library_nameObject



72
73
74
# File 'lib/alma/bib_item.rb', line 72

def holding_library_name
  item_data.dig("library", "desc")
end

#holding_locationObject



76
77
78
# File 'lib/alma/bib_item.rb', line 76

def holding_location
  item_data.dig("location", "value")
end

#holding_location_nameObject



80
81
82
# File 'lib/alma/bib_item.rb', line 80

def holding_location_name
  item_data.dig("location", "desc")
end

#in_place?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/alma/bib_item.rb', line 140

def in_place?
  base_status == "1"
end

#in_temp_location?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/alma/bib_item.rb', line 48

def in_temp_location?
  holding_data.fetch("in_temp_location", false)
end

#item_dataObject



44
45
46
# File 'lib/alma/bib_item.rb', line 44

def item_data
  @item.fetch("item_data", {})
end

#libraryObject



52
53
54
# File 'lib/alma/bib_item.rb', line 52

def library
  in_temp_location? ? temp_library : holding_library
end

#library_nameObject



56
57
58
# File 'lib/alma/bib_item.rb', line 56

def library_name
  in_temp_location? ? temp_library_name : holding_library_name
end

#locationObject



60
61
62
# File 'lib/alma/bib_item.rb', line 60

def location
  in_temp_location? ? temp_location : holding_location
end

#location_nameObject



64
65
66
# File 'lib/alma/bib_item.rb', line 64

def location_name
  in_temp_location? ? temp_location_name : holding_location_name
end

#missing_or_lost?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/alma/bib_item.rb', line 132

def missing_or_lost?
  !!process_type.match(/MISSING|LOST_LOAN/)
end

#non_circulating?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/alma/bib_item.rb', line 148

def non_circulating?
  circulation_policy.include?("Non-circulating")
end

#physical_material_typeObject



156
157
158
# File 'lib/alma/bib_item.rb', line 156

def physical_material_type
  item_data.fetch("physical_material_type", "")
end

#process_typeObject



128
129
130
# File 'lib/alma/bib_item.rb', line 128

def process_type
  item_data.dig("process_type", "value") || ""
end

#public_noteObject



160
161
162
# File 'lib/alma/bib_item.rb', line 160

def public_note
  item_data.fetch("public_note", "")
end

#temp_call_numberObject



100
101
102
# File 'lib/alma/bib_item.rb', line 100

def temp_call_number
  holding_data.fetch("temp_call_number", "")
end

#temp_libraryObject



84
85
86
# File 'lib/alma/bib_item.rb', line 84

def temp_library
  holding_data.dig("temp_library", "value")
end

#temp_library_nameObject



88
89
90
# File 'lib/alma/bib_item.rb', line 88

def temp_library_name
  holding_data.dig("temp_library", "desc")
end

#temp_locationObject



92
93
94
# File 'lib/alma/bib_item.rb', line 92

def temp_location
  holding_data.dig("temp_location", "value")
end

#temp_location_nameObject



96
97
98
# File 'lib/alma/bib_item.rb', line 96

def temp_location_name
  holding_data.dig("temp_location", "desc")
end