Class: AlternateValue

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::AttributeAnnotations, Shared::DualAnnotator, Shared::IsData
Defined in:
app/models/alternate_value.rb

Overview

AlternateValue(s) are annotations on an object or object attribute. Use only when the annotations are related to the same thing. (e.g. HernĂ¡n vs. Hernan, NOT Bean Books (publisher1) vs. Dell Books (publisher2))

Direct Known Subclasses

Abbreviation, AlternateSpelling, Misspelling, Translation

Defined Under Namespace

Classes: Abbreviation, AlternateSpelling, Misspelling, Translation

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (String) alternate_value_object_attribute

Returns the attribute (column) that this is an alternate value for

Returns:

  • (String)

    the attribute (column) that this is an alternate value for



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/alternate_value.rb', line 32

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations

  belongs_to :alternate_value_object, polymorphic: true
  belongs_to :language

  validates :language, presence: true, allow_blank: true

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates_presence_of :type, :value, :alternate_value_object_attribute

  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  def klass_name
    self.class.class_name
  end

  # @return [NoteObject]
  #   alias to simplify reference across classes
  def annotated_object
    alternate_value_object
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

end

- (String) alternate_value_object_type

the kind of thing being annotated

Returns:

  • (String)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/alternate_value.rb', line 32

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations

  belongs_to :alternate_value_object, polymorphic: true
  belongs_to :language

  validates :language, presence: true, allow_blank: true

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates_presence_of :type, :value, :alternate_value_object_attribute

  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  def klass_name
    self.class.class_name
  end

  # @return [NoteObject]
  #   alias to simplify reference across classes
  def annotated_object
    alternate_value_object
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

end

- (Integer) attribute_value_object_id

the ID of the thing being annotated

Returns:

  • (Integer)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/alternate_value.rb', line 32

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations

  belongs_to :alternate_value_object, polymorphic: true
  belongs_to :language

  validates :language, presence: true, allow_blank: true

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates_presence_of :type, :value, :alternate_value_object_attribute

  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  def klass_name
    self.class.class_name
  end

  # @return [NoteObject]
  #   alias to simplify reference across classes
  def annotated_object
    alternate_value_object
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

end

- (Integer) language_id

the ID of the language used for translation

Returns:

  • (Integer)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/alternate_value.rb', line 32

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations

  belongs_to :alternate_value_object, polymorphic: true
  belongs_to :language

  validates :language, presence: true, allow_blank: true

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates_presence_of :type, :value, :alternate_value_object_attribute

  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  def klass_name
    self.class.class_name
  end

  # @return [NoteObject]
  #   alias to simplify reference across classes
  def annotated_object
    alternate_value_object
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

end

- (Integer) project_id

the project ID

Returns:

  • (Integer)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/alternate_value.rb', line 32

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations

  belongs_to :alternate_value_object, polymorphic: true
  belongs_to :language

  validates :language, presence: true, allow_blank: true

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates_presence_of :type, :value, :alternate_value_object_attribute

  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  def klass_name
    self.class.class_name
  end

  # @return [NoteObject]
  #   alias to simplify reference across classes
  def annotated_object
    alternate_value_object
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

end

- (String) type

the annotated type

Returns:

  • (String)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/alternate_value.rb', line 32

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations

  belongs_to :alternate_value_object, polymorphic: true
  belongs_to :language

  validates :language, presence: true, allow_blank: true

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates_presence_of :type, :value, :alternate_value_object_attribute

  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  def klass_name
    self.class.class_name
  end

  # @return [NoteObject]
  #   alias to simplify reference across classes
  def annotated_object
    alternate_value_object
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

end

- (String) value

the annotated value

Returns:

  • (String)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/models/alternate_value.rb', line 32

class AlternateValue < ApplicationRecord
  include Housekeeping
  include Shared::IsData
  include Shared::DualAnnotator
  include Shared::AttributeAnnotations

  belongs_to :alternate_value_object, polymorphic: true
  belongs_to :language

  validates :language, presence: true, allow_blank: true

  # Please DO NOT include the following:
  # validates :alternate_value_object, presence: true

  validates_presence_of :type, :value, :alternate_value_object_attribute

  validates_uniqueness_of :value, scope: [:alternate_value_object, :type, :alternate_value_object_attribute, :project_id] # !! think about project/community on same object

  def type_name
    r = self.type.to_s
    ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
  end

  def type_class=(value)
    write_attribute(:type, value.to_s)
  end

  def type_class
    r = read_attribute(:type).to_s
    r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
  end

  def self.class_name
    self.name.demodulize.underscore.humanize.downcase
  end

  def self.find_for_autocomplete(params)
    where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
          "%#{params[:term]}%", params[:project_id])
  end

  def klass_name
    self.class.class_name
  end

  # @return [NoteObject]
  #   alias to simplify reference across classes
  def annotated_object
    alternate_value_object
  end

  # @return [Symbol]
  #   the column name containing the attribute name being annotated
  def self.annotated_attribute_column
    :alternate_value_object_attribute
  end

  def self.annotation_value_column
    :value
  end

  def self.generate_download(scope)
    CSV.generate do |csv|
      csv << column_names
      scope.order(id: :asc).find_each do |o|
        csv << o.attributes.values_at(*column_names).collect { |i|
          i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
        }
      end
    end
  end

end

Class Method Details

+ (Symbol) annotated_attribute_column

Returns the column name containing the attribute name being annotated

Returns:

  • (Symbol)

    the column name containing the attribute name being annotated



85
86
87
# File 'app/models/alternate_value.rb', line 85

def self.annotated_attribute_column
  :alternate_value_object_attribute
end

+ (Object) annotation_value_column



89
90
91
# File 'app/models/alternate_value.rb', line 89

def self.annotation_value_column
  :value
end

+ (Object) class_name



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

def self.class_name
  self.name.demodulize.underscore.humanize.downcase
end

+ (Object) find_for_autocomplete(params)



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

def self.find_for_autocomplete(params)
  where('value ILIKE ? AND ((project_id IS NULL) OR (project_id = ?))',
        "%#{params[:term]}%", params[:project_id])
end

+ (Object) generate_download(scope)



93
94
95
96
97
98
99
100
101
102
# File 'app/models/alternate_value.rb', line 93

def self.generate_download(scope)
  CSV.generate do |csv|
    csv << column_names
    scope.order(id: :asc).find_each do |o|
      csv << o.attributes.values_at(*column_names).collect { |i|
        i.to_s.gsub(/\n/, '\n').gsub(/\t/, '\t')
      }
    end
  end
end

Instance Method Details

- (NoteObject) annotated_object

Returns alias to simplify reference across classes

Returns:

  • (NoteObject)

    alias to simplify reference across classes



79
80
81
# File 'app/models/alternate_value.rb', line 79

def annotated_object
  alternate_value_object
end

- (Object) klass_name



73
74
75
# File 'app/models/alternate_value.rb', line 73

def klass_name
  self.class.class_name
end

- (Object) type_class



59
60
61
62
# File 'app/models/alternate_value.rb', line 59

def type_class
  r = read_attribute(:type).to_s
  r = ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r.safe_constantize : nil
end

- (Object) type_class=(value)



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

def type_class=(value)
  write_attribute(:type, value.to_s)
end

- (Object) type_name



50
51
52
53
# File 'app/models/alternate_value.rb', line 50

def type_name
  r = self.type.to_s
  ALTERNATE_VALUE_CLASS_NAMES.include?(r) ? r : nil
end