Class: ShopifyApp
- Inherits:
-
Object
- Object
- ShopifyApp
- Extended by:
- Concerns::Findable, Concerns::Methods::ClassMethods
- Includes:
- Concerns::Methods::InstanceMethods
- Defined in:
- lib/shopify_app_reviews/shopify_app.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#app_reviews ⇒ Object
Returns the value of attribute app_reviews.
-
#category ⇒ Object
Returns the value of attribute category.
-
#description ⇒ Object
Returns the value of attribute description.
-
#developer_contact ⇒ Object
Returns the value of attribute developer_contact.
-
#developer_name ⇒ Object
Returns the value of attribute developer_name.
-
#developer_url ⇒ Object
Returns the value of attribute developer_url.
-
#name ⇒ Object
Returns the value of attribute name.
-
#overall_rating ⇒ Object
Returns the value of attribute overall_rating.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ ShopifyApp
constructor
A new instance of ShopifyApp.
- #overall_sentiment ⇒ Object
- #set_sentiment(rating_type) ⇒ Object
- #total_review_count ⇒ Object
- #trending_sentiment ⇒ Object
Methods included from Concerns::Findable
Methods included from Concerns::Methods::ClassMethods
Methods included from Concerns::Methods::InstanceMethods
Constructor Details
#initialize(attributes) ⇒ ShopifyApp
Returns a new instance of ShopifyApp.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 10 def initialize(attributes) @name = attributes[:name] @url = attributes[:url] @category = attributes[:category] @developer_name = attributes[:developer_name] @developer_url = attributes[:developer_url] @description = attributes[:description] if attributes[:description] @overall_rating = attributes[:overall_rating] if attributes[:overall_rating] @developer_contact = attributes[:developer_contact] if attributes[:developer_contact] @app_reviews = [] end |
Instance Attribute Details
#app_reviews ⇒ Object
Returns the value of attribute app_reviews.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def app_reviews @app_reviews end |
#category ⇒ Object
Returns the value of attribute category.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def category @category end |
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def description @description end |
#developer_contact ⇒ Object
Returns the value of attribute developer_contact.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def developer_contact @developer_contact end |
#developer_name ⇒ Object
Returns the value of attribute developer_name.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def developer_name @developer_name end |
#developer_url ⇒ Object
Returns the value of attribute developer_url.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def developer_url @developer_url end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def name @name end |
#overall_rating ⇒ Object
Returns the value of attribute overall_rating.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def @overall_rating end |
#url ⇒ Object
Returns the value of attribute url.
2 3 4 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2 def url @url end |
Class Method Details
.all ⇒ Object
22 23 24 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 22 def self.all @@all end |
.create_from_collection(app_array) ⇒ Object
69 70 71 72 73 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 69 def self.create_from_collection(app_array) app_array.each do |app_info| self.create(app_info) end end |
Instance Method Details
#overall_sentiment ⇒ Object
55 56 57 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 55 def overall_sentiment set_sentiment(self.) end |
#set_sentiment(rating_type) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 38 def set_sentiment() sentiment = "Unknown" if .is_a?(String) = .split(" ").first = .to_f else = end sentiment = "terrible (#{}/5)".colorize(:red) if .between?(0.00,0.999) sentiment = "really bad (#{}/5)".colorize(:red) if .between?(1.00,1.999) sentiment = "OK at best (#{}/5)".colorize(:yellow) if .between?(2.00,2.999) sentiment = "good (#{}/5)".colorize(:yellow) if .between?(3.00,3.999) sentiment = "great (#{}/5)".colorize(:cyan) if .between?(4.00,4.499) sentiment = "excellent (#{}/5)".colorize(:cyan) if .between?(4.50,5.00) sentiment end |
#total_review_count ⇒ Object
34 35 36 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 34 def total_review_count app_reviews.count end |
#trending_sentiment ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/shopify_app_reviews/shopify_app.rb', line 59 def trending_sentiment = [] self.app_reviews.each do |review| = review..split(" ").first.to_f << end = .reduce(:+) / .size set_sentiment() end |