Class: Item

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/item.rb,
app/models2/item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#library_idObject

Returns the value of attribute library_id.



64
65
66
# File 'app/models/item.rb', line 64

def library_id
  @library_id
end

Class Method Details

.csv_header(role: 'Guest') ⇒ Object



102
103
104
# File 'app/models/item.rb', line 102

def self.csv_header(role: 'Guest')
  Item.new.to_hash(role: role).keys
end

Instance Method Details

#contributorObject



76
77
78
# File 'app/models/item.rb', line 76

def contributor
  manifestation&.contributor
end

#creatorObject



72
73
74
# File 'app/models/item.rb', line 72

def creator
  manifestation&.creator
end

#manifestation_urlObject



88
89
90
# File 'app/models/item.rb', line 88

def manifestation_url
  Addressable::URI.parse("#{LibraryGroup.site_config.url}manifestations/#{self.manifestation.id}").normalize.to_s if self.manifestation
end

#owned(agent) ⇒ Object



84
85
86
# File 'app/models/item.rb', line 84

def owned(agent)
  owns.find_by(agent_id: agent.id)
end

#publisherObject



80
81
82
# File 'app/models/item.rb', line 80

def publisher
  manifestation&.publisher
end

#removable?Boolean

Returns:

  • (Boolean)


92
93
94
95
96
97
98
99
100
# File 'app/models/item.rb', line 92

def removable?
  if defined?(EnjuCirculation)
    return false if circulation_status.name == 'Removed'
    return false if checkouts.exists?
    true
  else
    true
  end
end

#titleObject



68
69
70
# File 'app/models/item.rb', line 68

def title
  manifestation&.original_title
end

#to_hash(role: 'Guest') ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/models/item.rb', line 106

def to_hash(role: 'Guest')
  record = {
    item_id: id,
    item_identifier: item_identifier,
    binding_item_identifier: binding_item_identifier,
    call_number: call_number,
    library: shelf&.library&.name,
    shelf: shelf&.name,
    item_note: note,
    accepted_at: accept&.created_at,
    acquired_at: acquired_at,
    item_created_at: created_at,
    item_updated_at: updated_at
  }

  if ['Administrator', 'Librarian'].include?(role)
    record.merge!({
      bookstore: bookstore&.name,
      budget_type: budget_type&.name,
      item_required_role: required_role.name,
      item_price: price,
      item_memo: memo
    })

    ItemCustomProperty.order(:position).each do |custom_property|
      custom_value = item_custom_values.find_by(item_custom_property: custom_property)
      record[:"item:#{custom_property.name}"] = custom_value.try(:value)
    end

    if defined?(EnjuCirculation)
      record.merge!({
        use_restriction: use_restriction&.name,
        circulation_status: circulation_status&.name,
        checkout_type: checkout_type&.name,
        total_checkouts: checkouts.count
      })
    end
  end

  record
end