Class: Finlight::Article

Inherits:
RawArticle show all
Defined in:
lib/finlight/models.rb

Overview

An enriched article with sentiment, entities and content.

Instance Attribute Summary collapse

Attributes inherited from RawArticle

#categories, #created_at, #images, #is_update, #language, #link, #publish_date, #revised_date, #source, #summary, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RawArticle

base_attributes

Constructor Details

#initialize(sentiment: nil, confidence: nil, content: nil, companies: nil, countries: nil, **base) ⇒ Article

Returns a new instance of Article.



128
129
130
131
132
133
134
135
136
# File 'lib/finlight/models.rb', line 128

def initialize(sentiment: nil, confidence: nil, content: nil, companies: nil,
               countries: nil, **base)
  super(**base)
  @sentiment = sentiment
  @confidence = confidence
  @content = content
  @companies = companies
  @countries = countries
end

Instance Attribute Details

#companiesObject (readonly)

Returns the value of attribute companies.



126
127
128
# File 'lib/finlight/models.rb', line 126

def companies
  @companies
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



126
127
128
# File 'lib/finlight/models.rb', line 126

def confidence
  @confidence
end

#contentObject (readonly)

Returns the value of attribute content.



126
127
128
# File 'lib/finlight/models.rb', line 126

def content
  @content
end

#countriesObject (readonly)

Returns the value of attribute countries.



126
127
128
# File 'lib/finlight/models.rb', line 126

def countries
  @countries
end

#sentimentObject (readonly)

Returns the value of attribute sentiment.



126
127
128
# File 'lib/finlight/models.rb', line 126

def sentiment
  @sentiment
end

Class Method Details

.from_h(hash) ⇒ Object



138
139
140
141
142
143
144
145
146
147
# File 'lib/finlight/models.rb', line 138

def self.from_h(hash)
  new(
    **base_attributes(hash),
    sentiment: hash["sentiment"],
    confidence: ModelParsing.to_float(hash["confidence"]),
    content: hash["content"],
    companies: hash["companies"]&.map { |c| Company.from_h(c) },
    countries: ModelParsing.to_string_list(hash["countries"])
  )
end