Class: GeoLabels::RatingList
- Inherits:
-
Object
- Object
- GeoLabels::RatingList
- Includes:
- Enumerable
- Defined in:
- app/models/concerns/geo_labels/ratings_support.rb
Overview
Represent the possible rating objects for the topics as a list
Defined Under Namespace
Classes: OutOfBoundIndex
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#[]=(topic, value) ⇒ Object
allow short hand assign record.rating = 3.
- #each(&block) ⇒ Object
-
#initialize(record) ⇒ RatingList
constructor
A new instance of RatingList.
- #object_list ⇒ Object
Constructor Details
#initialize(record) ⇒ RatingList
Returns a new instance of RatingList.
33 34 35 |
# File 'app/models/concerns/geo_labels/ratings_support.rb', line 33 def initialize(record) @record = record end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
31 32 33 |
# File 'app/models/concerns/geo_labels/ratings_support.rb', line 31 def record @record end |
Instance Method Details
#[](index) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/concerns/geo_labels/ratings_support.rb', line 49 def [](index) case index when String then RatingObject.new(record, index.to_sym) when Symbol then RatingObject.new(record, index) when Integer topic = record.class.[index] raise OutOfBoundIndex, 'Rating list index provided is out of bounds' unless topic RatingObject.new(record, topic) else raise OutOfBoundIndex, 'Rating list index provided is out of bounds' end end |
#[]=(topic, value) ⇒ Object
allow short hand assign
record.[:food] = 3
65 66 67 |
# File 'app/models/concerns/geo_labels/ratings_support.rb', line 65 def []=(topic, value) self[topic].value = value end |
#each(&block) ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/models/concerns/geo_labels/ratings_support.rb', line 37 def each(&block) if block_given? object_list.each(&block) else to_enum(:each) end end |
#object_list ⇒ Object
45 46 47 |
# File 'app/models/concerns/geo_labels/ratings_support.rb', line 45 def object_list record.class..map { |topic| RatingObject.new(record, topic) } end |