Class: Completeness::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/completeness/specification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpecification

Returns a new instance of Specification.



5
6
7
# File 'lib/completeness/specification.rb', line 5

def initialize
  @attributes = {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/completeness/specification.rb', line 3

def attributes
  @attributes
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
# File 'lib/completeness/specification.rb', line 9

def [](key)
  attributes[key]
end

#[]=(key, value) ⇒ Object



13
14
15
# File 'lib/completeness/specification.rb', line 13

def []=(key, value)
  attributes[key] = value
end

#all_attributesObject



17
18
19
# File 'lib/completeness/specification.rb', line 17

def all_attributes
  @all_attributes ||= attributes.values
end

#completed?(object) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/completeness/specification.rb', line 45

def completed?(object)
  required_attributes.all?{|attribute| attribute.completed?(object)}
end

#completed_percent(object) ⇒ Object



41
42
43
# File 'lib/completeness/specification.rb', line 41

def completed_percent(object)
  (completed_weight(object) / (total_weight / 100.0)).round
end

#completed_weight(object) ⇒ Object



37
38
39
# File 'lib/completeness/specification.rb', line 37

def completed_weight(object)
  completed_attributes_for(object).sum(&:weight)
end

#recomend_next_attribute_for(object) ⇒ Object



29
30
31
# File 'lib/completeness/specification.rb', line 29

def recomend_next_attribute_for(object)
  weighted_uncompleted_attributes_for(object).first
end

#required_attributesObject



21
22
23
# File 'lib/completeness/specification.rb', line 21

def required_attributes
  all_attributes.select(&:required?)
end

#total_weightObject



25
26
27
# File 'lib/completeness/specification.rb', line 25

def total_weight
  all_attributes.sum(&:weight)
end

#weighted_uncompleted_attributes_for(object) ⇒ Object



33
34
35
# File 'lib/completeness/specification.rb', line 33

def weighted_uncompleted_attributes_for(object)
  uncompleted_attributes_for(object).sort.reverse
end