To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / plugins / redmine_bibliography / app / models / author.rb @ 1419:fd6b09e93623
History | View | Annotate | Download (832 Bytes)
| 1 | 328:aed18b463206 | luis | class Author < ActiveRecord::Base |
|---|---|---|---|
| 2 | 946:a0c9cc95bcf3 | luis | unloadable |
| 3 | 1123:48c5fdd6cf10 | luis | |
| 4 | 468:0bb9c7baed07 | luis | has_many :authorships, :dependent => :destroy |
| 5 | 328:aed18b463206 | luis | has_many :publications, :through => :authorships |
| 6 | 403:b15397a5341c | luis | |
| 7 | 466:a7dc708d48a1 | luis | belongs_to :user
|
| 8 | 478:7097dc91e58e | luis | |
| 9 | def <=>(author) |
||
| 10 | name.downcase <=> author.name.downcase |
||
| 11 | end
|
||
| 12 | 1123:48c5fdd6cf10 | luis | |
| 13 | 1124:807426fa6017 | luis | # todo: review usage of scope --lf.20130108
|
| 14 | 1123:48c5fdd6cf10 | luis | scope :like, lambda {|q|
|
| 15 | 477:aeedcec4df5f | luis | s = "%#{q.to_s.strip.downcase}%"
|
| 16 | {:conditions => ["LOWER(name) LIKE :s", {:s => s}],
|
||
| 17 | :order => 'name' |
||
| 18 | } |
||
| 19 | 478:7097dc91e58e | luis | } |
| 20 | |||
| 21 | 1412:48d9b3ae9e1a | luis | def institution |
| 22 | 1413:0e40e05048eb | luis | if self.authorships.first.nil? |
| 23 | ""
|
||
| 24 | else
|
||
| 25 | self.authorships.first.institution
|
||
| 26 | end
|
||
| 27 | 1412:48d9b3ae9e1a | luis | end
|
| 28 | 1414:07444815c0bd | luis | |
| 29 | def mail |
||
| 30 | if self.authorships.first.nil? |
||
| 31 | ""
|
||
| 32 | else
|
||
| 33 | self.authorships.first.mail
|
||
| 34 | end
|
||
| 35 | end
|
||
| 36 | |||
| 37 | 1417:1df2db7f0e4d | luis | def name |
| 38 | 1419:fd6b09e93623 | luis | if self.name.nil? |
| 39 | if self.authorships.first.nil? |
||
| 40 | ""
|
||
| 41 | else
|
||
| 42 | self.authorships.first.name
|
||
| 43 | end
|
||
| 44 | 1417:1df2db7f0e4d | luis | end
|
| 45 | end
|
||
| 46 | |||
| 47 | 328:aed18b463206 | luis | end |