Class: Opinions::OpinionFactory
- Inherits:
-
Object
- Object
- Opinions::OpinionFactory
- Defined in:
- lib/opinions.rb
Instance Attribute Summary collapse
-
#key_name ⇒ Object
readonly
Returns the value of attribute key_name.
Instance Method Summary collapse
-
#initialize(args) ⇒ OpinionFactory
constructor
A new instance of OpinionFactory.
- #opinion ⇒ Object
Constructor Details
#initialize(args) ⇒ OpinionFactory
Returns a new instance of OpinionFactory.
42 43 44 45 |
# File 'lib/opinions.rb', line 42 def initialize(args) @direction = args.has_key?(:from_target) ? :ot : :to @key_name = args.first[1] end |
Instance Attribute Details
#key_name ⇒ Object (readonly)
Returns the value of attribute key_name.
41 42 43 |
# File 'lib/opinions.rb', line 41 def key_name @key_name end |
Instance Method Details
#opinion ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opinions.rb', line 46 def opinion Opinions.backend.read_key(key_name).collect do |object_id, time| target_class_name, opinion, target_id, object_class_name = key_name.split ':' target_class, object_class = Kernel.const_get(target_class_name), Kernel.const_get(object_class_name) Opinion.new(target: (@direction == :to ? object_class.find(object_id) : target_class.find(target_id)), object: (@direction == :to ? target_class.find(target_id) : object_class.find(object_id)), opinion: opinion.to_sym, created_at: time) end end |