Class: Abstract
- Inherits:
-
ActiveRecordShared
- Object
- ActiveRecord::Base
- ActiveRecordShared
- Abstract
- Includes:
- AbstractValidations
- Defined in:
- app/models/abstract.rb
Overview
Abstract model
Instance Attribute Summary collapse
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#height_units ⇒ Object
Returns the value of attribute height_units.
-
#merging ⇒ Object
flag to be used to skip 2 abstract limitation.
-
#weight_units ⇒ Object
Returns the value of attribute weight_units.
Class Method Summary collapse
- .db_fields ⇒ Object
- .fields ⇒ Object
-
.search(params = {}) ⇒ Object
include AbstractSearch.
- .sections ⇒ Object
Instance Method Summary collapse
- #comparable_attributes ⇒ Object
- #db_fields ⇒ Object
- #diff(another_abstract) ⇒ Object
- #fields ⇒ Object
- #is_the_same_as?(another_abstract) ⇒ Boolean
- #merged? ⇒ Boolean
Methods included from AbstractValidations
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
19 20 21 |
# File 'app/models/abstract.rb', line 19 def current_user @current_user end |
#height_units ⇒ Object
Returns the value of attribute height_units.
20 21 22 |
# File 'app/models/abstract.rb', line 20 def height_units @height_units end |
#merging ⇒ Object
flag to be used to skip 2 abstract limitation
21 22 23 |
# File 'app/models/abstract.rb', line 21 def merging @merging end |
#weight_units ⇒ Object
Returns the value of attribute weight_units.
20 21 22 |
# File 'app/models/abstract.rb', line 20 def weight_units @weight_units end |
Class Method Details
.db_fields ⇒ Object
46 47 48 49 |
# File 'app/models/abstract.rb', line 46 def self.db_fields # @db_fields ||= fields.collect{|f|f[:db]} Abstract.fields.collect{|f|f[:db]} end |
.fields ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/abstract.rb', line 34 def self.fields # db: db field name # human: humanized field @@fields ||= YAML::load( ERB.new( IO.read( File.join(File.dirname(__FILE__),'../../config/abstract_fields.yml') )).result) end |
.search(params = {}) ⇒ Object
include AbstractSearch
70 71 72 73 74 75 |
# File 'app/models/abstract.rb', line 70 def self.search(params={}) # TODO stop using this. Now that study subjects and abstracts are in # the same database, this should be simplified. Particularly since # the only searching is really on the study subject and not the abstract. AbstractSearch.new(params).abstracts end |
.sections ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'app/models/abstract.rb', line 77 def self.sections # :label: Cytogenetics # :controller: CytogeneticsController # :edit: :edit_abstract_cytogenetic_path # :show: :abstract_cytogenetic_path @@sections ||= YAML::load(ERB.new( IO.read( File.join(File.dirname(__FILE__),'../../config/abstract_sections.yml') )).result) end |
Instance Method Details
#comparable_attributes ⇒ Object
55 56 57 |
# File 'app/models/abstract.rb', line 55 def comparable_attributes HashWithIndifferentAccess[attributes.select {|k,v| db_fields.include?(k)}] end |
#db_fields ⇒ Object
51 52 53 |
# File 'app/models/abstract.rb', line 51 def db_fields Abstract.db_fields end |
#diff(another_abstract) ⇒ Object
63 64 65 66 67 |
# File 'app/models/abstract.rb', line 63 def diff(another_abstract) a1 = self.comparable_attributes a2 = Abstract.find(another_abstract).comparable_attributes HashWithIndifferentAccess[a1.select{|k,v| a2[k] != v unless( a2[k].blank? && v.blank? ) }] end |
#is_the_same_as?(another_abstract) ⇒ Boolean
59 60 61 |
# File 'app/models/abstract.rb', line 59 def is_the_same_as?(another_abstract) self.diff(another_abstract).blank? end |
#merged? ⇒ Boolean
87 88 89 |
# File 'app/models/abstract.rb', line 87 def merged? !merged_by_uid.blank? end |