@@ -77,25 +77,25 @@ def has_duplicate_annotation?(annotation)
77
77
78
78
#A set of all values that have been used, or seeded, with one of the provided attribute names
79
79
def with_attribute_names attributes
80
- #TODO: this would probably be better as a named_scope
81
80
attributes = Array ( attributes )
82
- attributes . reduce ( [ ] ) { |values , attr |
83
- annotations = Annotation . with_attribute_name ( attr ) . with_value_type ( self . name ) . include_values . collect { |ann | ann . value }
84
- seeds = AnnotationValueSeed . with_attribute_name ( attr ) . with_value_type ( self . name ) . include_values . collect { |ann | ann . value }
85
- values | annotations | seeds
86
- } . uniq
81
+ annotations = Annotation . with_attribute_names ( attributes ) . with_value_type ( self . name ) . include_values . collect { |ann | ann . value }
82
+ seeds = AnnotationValueSeed . with_attribute_names ( attributes ) . with_value_type ( self . name ) . include_values . collect { |ann | ann . value }
83
+ ( annotations | seeds ) . uniq
87
84
end
88
85
end
89
86
90
87
# This module contains instance methods
91
88
module InstanceMethods
92
89
90
+ #Whether this value exists with a given attribute name
91
+ def has_attribute_name? attr
92
+ !annotations . with_attribute_name ( attr ) . empty? || !annotation_value_seeds . with_attribute_name ( attr ) . empty?
93
+ end
94
+
93
95
#The total number of annotations that match one or more attribute names.
94
96
def annotation_count attributes
95
97
attributes = Array ( attributes )
96
- attributes . reduce ( 0 ) do |sum , attr |
97
- sum + annotations . with_attribute_name ( attr ) . count
98
- end
98
+ annotations . with_attribute_names ( attributes ) . count
99
99
end
100
100
101
101
# The actual content of the annotation value
0 commit comments