Class: Agent
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Agent
- Defined in:
- app/models/agent.rb
Class Method Summary collapse
Instance Method Summary collapse
- #agents ⇒ Object
- #check_birth_date ⇒ Object
- #created(work) ⇒ Object
- #creator?(resource) ⇒ Boolean
- #date ⇒ Object
- #full_name_alternative_without_space ⇒ Object
- #full_name_transcription_without_space ⇒ Object
-
#full_name_without_space ⇒ Object
def full_name_generate # TODO: 日本人以外は? name = [] name << self.last_name.to_s.strip name << self.middle_name.to_s.strip unless self.middle_name.blank? name << self.first_name.to_s.strip name << self.corporate_name.to_s.strip name.join(“ ”).strip end.
- #name ⇒ Object
- #owned(item) ⇒ Object
- #produced(manifestation) ⇒ Object
- #publisher?(resource) ⇒ Boolean
- #realized(expression) ⇒ Object
- #set_date_of_birth ⇒ Object
- #set_date_of_death ⇒ Object
- #set_full_name ⇒ Object
- #set_role_and_name ⇒ Object
Class Method Details
.import_agents(agent_lists) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'app/models/agent.rb', line 218 def self.import_agents(agent_lists) agents = [] agent_lists.each do |agent_list| name_and_role = agent_list[:full_name].split('||') if agent_list[:agent_identifier].present? agent = Agent.where(agent_identifier: agent_list[:agent_identifier]).first else agent = Agent.where(full_name: name_and_role[0]).first end role_type = name_and_role[1].to_s.strip unless agent agent = Agent.new( full_name: name_and_role[0], full_name_transcription: agent_list[:full_name_transcription], agent_identifier: agent_list[:agent_identifier], language_id: 1 ) agent.required_role = Role.where(name: 'Guest').first agent.save end agents << agent end agents end |
Instance Method Details
#agents ⇒ Object
243 244 245 |
# File 'app/models/agent.rb', line 243 def agents self.original_agents + self.derived_agents end |
#check_birth_date ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'app/models/agent.rb', line 132 def check_birth_date if date_of_birth.present? && date_of_death.present? if date_of_birth > date_of_death errors.add(:birth_date) errors.add(:death_date) end end end |
#created(work) ⇒ Object
202 203 204 |
# File 'app/models/agent.rb', line 202 def created(work) creates.where(work_id: work.id).first end |
#creator?(resource) ⇒ Boolean
194 195 196 |
# File 'app/models/agent.rb', line 194 def creator?(resource) resource.creators.include?(self) end |
#date ⇒ Object
184 185 186 187 188 189 190 191 192 |
# File 'app/models/agent.rb', line 184 def date if date_of_birth if date_of_death "#{date_of_birth} - #{date_of_death}" else "#{date_of_birth} -" end end end |
#full_name_alternative_without_space ⇒ Object
166 167 168 |
# File 'app/models/agent.rb', line 166 def full_name_alternative_without_space full_name_alternative.to_s.gsub(/\s/, "") end |
#full_name_transcription_without_space ⇒ Object
162 163 164 |
# File 'app/models/agent.rb', line 162 def full_name_transcription_without_space full_name_transcription.to_s.gsub(/\s/, "") end |
#full_name_without_space ⇒ Object
def full_name_generate
# TODO: 日本人以外は?
name = []
name << self.last_name.to_s.strip
name << self.middle_name.to_s.strip unless self.middle_name.blank?
name << self.first_name.to_s.strip
name << self.corporate_name.to_s.strip
name.join(" ").strip
end
151 152 153 154 155 156 157 158 159 160 |
# File 'app/models/agent.rb', line 151 def full_name_without_space full_name.gsub(/[\s,]/, "") # # TODO: 日本人以外は? # name = [] # name << self.last_name.to_s.strip # name << self.middle_name.to_s.strip # name << self.first_name.to_s.strip # name << self.corporate_name.to_s.strip # name.join("").strip end |
#name ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'app/models/agent.rb', line 170 def name name = [] name << full_name.to_s.strip name << full_name_transcription.to_s.strip name << full_name_alternative.to_s.strip name << full_name_without_space #name << full_name_transcription_without_space #name << full_name_alternative_without_space #name << full_name.wakati rescue nil #name << full_name_transcription.wakati rescue nil #name << full_name_alternative.wakati rescue nil name end |
#owned(item) ⇒ Object
214 215 216 |
# File 'app/models/agent.rb', line 214 def owned(item) owns.where(item_id: item.id) end |
#produced(manifestation) ⇒ Object
210 211 212 |
# File 'app/models/agent.rb', line 210 def produced(manifestation) produces.where(manifestation_id: manifestation.id).first end |
#publisher?(resource) ⇒ Boolean
198 199 200 |
# File 'app/models/agent.rb', line 198 def publisher?(resource) resource.publishers.include?(self) end |
#realized(expression) ⇒ Object
206 207 208 |
# File 'app/models/agent.rb', line 206 def realized(expression) realizes.where(expression_id: expression.id).first end |
#set_date_of_birth ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/agent.rb', line 95 def set_date_of_birth return if birth_date.blank? begin date = Time.zone.parse("#{birth_date}") rescue ArgumentError begin date = Time.zone.parse("#{birth_date}-01") rescue ArgumentError begin date = Time.zone.parse("#{birth_date}-01-01") rescue nil end end end self.date_of_birth = date end |
#set_date_of_death ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/agent.rb', line 113 def set_date_of_death return if death_date.blank? begin date = Time.zone.parse("#{death_date}") rescue ArgumentError begin date = Time.zone.parse("#{death_date}-01") rescue ArgumentError begin date = Time.zone.parse("#{death_date}-01-01") rescue nil end end end self.date_of_death = date end |
#set_full_name ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/models/agent.rb', line 81 def set_full_name if full_name.blank? if LibraryGroup.site_config.settings[:family_name_first] self.full_name = [last_name, middle_name, first_name].compact.join(" ").to_s.strip else self.full_name = [first_name, last_name, middle_name].compact.join(" ").to_s.strip end end if full_name_transcription.blank? self.full_name_transcription = [last_name_transcription, middle_name_transcription, first_name_transcription].join(" ").to_s.strip end [full_name, full_name_transcription] end |
#set_role_and_name ⇒ Object
76 77 78 79 |
# File 'app/models/agent.rb', line 76 def set_role_and_name self.required_role = Role.where(name: 'Librarian').first if required_role_id.nil? set_full_name end |