Class: Abstract

Inherits:
ActiveRecordShared show all
Includes:
AbstractValidations
Defined in:
app/models/abstract.rb

Overview

Abstract model

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AbstractValidations

included

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



19
20
21
# File 'app/models/abstract.rb', line 19

def current_user
  @current_user
end

#height_unitsObject

Returns the value of attribute height_units.



20
21
22
# File 'app/models/abstract.rb', line 20

def height_units
  @height_units
end

#mergingObject

flag to be used to skip 2 abstract limitation



21
22
23
# File 'app/models/abstract.rb', line 21

def merging
  @merging
end

#weight_unitsObject

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_fieldsObject



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

.fieldsObject



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

.sectionsObject



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_attributesObject



55
56
57
# File 'app/models/abstract.rb', line 55

def comparable_attributes
	HashWithIndifferentAccess[attributes.select {|k,v| db_fields.include?(k)}]
end

#db_fieldsObject



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

#fieldsObject



42
43
44
# File 'app/models/abstract.rb', line 42

def fields
	Abstract.fields
end

#is_the_same_as?(another_abstract) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


87
88
89
# File 'app/models/abstract.rb', line 87

def merged?
	!merged_by_uid.blank?
end