Class: Completeness::Specification
- Inherits:
-
Object
- Object
- Completeness::Specification
- Defined in:
- lib/completeness/specification.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #all_attributes ⇒ Object
- #completed?(object) ⇒ Boolean
- #completed_percent(object) ⇒ Object
- #completed_weight(object) ⇒ Object
-
#initialize ⇒ Specification
constructor
A new instance of Specification.
- #recomend_next_attribute_for(object) ⇒ Object
- #required_attributes ⇒ Object
- #total_weight ⇒ Object
- #weighted_uncompleted_attributes_for(object) ⇒ Object
Constructor Details
#initialize ⇒ Specification
Returns a new instance of Specification.
5 6 7 |
# File 'lib/completeness/specification.rb', line 5 def initialize @attributes = {} end |
Instance Attribute Details
#attributes ⇒ Object (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_attributes ⇒ Object
17 18 19 |
# File 'lib/completeness/specification.rb', line 17 def all_attributes @all_attributes ||= attributes.values end |
#completed?(object) ⇒ 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_attributes ⇒ Object
21 22 23 |
# File 'lib/completeness/specification.rb', line 21 def required_attributes all_attributes.select(&:required?) end |
#total_weight ⇒ Object
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 |