Class: Broadlistening::Comment
- Inherits:
-
Object
- Object
- Broadlistening::Comment
- Defined in:
- lib/broadlistening/comment.rb
Overview
Represents a normalized comment in the pipeline.
Comments are the input data to the pipeline, containing user opinions that will be processed into arguments through the extraction step.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#body ⇒ Object
Returns the value of attribute body.
-
#id ⇒ Object
Returns the value of attribute id.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#proposal_id ⇒ Object
Returns the value of attribute proposal_id.
-
#source_url ⇒ Object
Returns the value of attribute source_url.
Class Method Summary collapse
-
.from_hash(hash, property_names: []) ⇒ Comment
Create a Comment from a hash, normalizing various input formats.
-
.from_object(obj, property_names: []) ⇒ Comment
Create a Comment from an object (e.g., ActiveRecord model).
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Check if comment body is empty or nil.
-
#initialize(id:, body:, proposal_id: nil, source_url: nil, attributes: nil, properties: nil) ⇒ Comment
constructor
A new instance of Comment.
-
#to_h ⇒ Hash
Convert to hash for serialization.
Constructor Details
#initialize(id:, body:, proposal_id: nil, source_url: nil, attributes: nil, properties: nil) ⇒ Comment
Returns a new instance of Comment.
17 18 19 20 21 22 23 24 |
# File 'lib/broadlistening/comment.rb', line 17 def initialize(id:, body:, proposal_id: nil, source_url: nil, attributes: nil, properties: nil) @id = id @body = body @proposal_id = proposal_id @source_url = source_url @attributes = attributes @properties = properties end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
15 16 17 |
# File 'lib/broadlistening/comment.rb', line 15 def attributes @attributes end |
#body ⇒ Object
Returns the value of attribute body.
15 16 17 |
# File 'lib/broadlistening/comment.rb', line 15 def body @body end |
#id ⇒ Object
Returns the value of attribute id.
15 16 17 |
# File 'lib/broadlistening/comment.rb', line 15 def id @id end |
#properties ⇒ Object
Returns the value of attribute properties.
15 16 17 |
# File 'lib/broadlistening/comment.rb', line 15 def properties @properties end |
#proposal_id ⇒ Object
Returns the value of attribute proposal_id.
15 16 17 |
# File 'lib/broadlistening/comment.rb', line 15 def proposal_id @proposal_id end |
#source_url ⇒ Object
Returns the value of attribute source_url.
15 16 17 |
# File 'lib/broadlistening/comment.rb', line 15 def source_url @source_url end |
Class Method Details
.from_hash(hash, property_names: []) ⇒ Comment
Create a Comment from a hash, normalizing various input formats
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/broadlistening/comment.rb', line 31 def self.from_hash(hash, property_names: []) new( id: hash[:id] || hash["id"], body: hash[:body] || hash["body"], proposal_id: hash[:proposal_id] || hash["proposal_id"], source_url: extract_source_url(hash), attributes: extract_attributes(hash), properties: extract_properties(hash, property_names) ) end |
.from_object(obj, property_names: []) ⇒ Comment
Create a Comment from an object (e.g., ActiveRecord model)
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/broadlistening/comment.rb', line 47 def self.from_object(obj, property_names: []) new( id: obj.id, body: obj.body, proposal_id: obj.respond_to?(:proposal_id) ? obj.proposal_id : nil, source_url: obj.respond_to?(:source_url) ? obj.source_url : nil, attributes: extract_attributes_from_object(obj), properties: extract_properties_from_object(obj, property_names) ) end |
Instance Method Details
#empty? ⇒ Boolean
Check if comment body is empty or nil
75 76 77 |
# File 'lib/broadlistening/comment.rb', line 75 def empty? @body.nil? || @body.strip.empty? end |
#to_h ⇒ Hash
Convert to hash for serialization
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/broadlistening/comment.rb', line 61 def to_h { id: @id, body: @body, proposal_id: @proposal_id, source_url: @source_url, attributes: @attributes, properties: @properties } end |