Class: ShopifyApp

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Findable

find_by_name, find_by_url

Methods included from Concerns::Methods::ClassMethods

create, destroy_all

Methods included from Concerns::Methods::InstanceMethods

#save

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_reviewsObject

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

#categoryObject

Returns the value of attribute category.



2
3
4
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2

def category
  @category
end

#descriptionObject

Returns the value of attribute description.



2
3
4
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2

def description
  @description
end

#developer_contactObject

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_nameObject

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_urlObject

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

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2

def name
  @name
end

#overall_ratingObject

Returns the value of attribute overall_rating.



2
3
4
# File 'lib/shopify_app_reviews/shopify_app.rb', line 2

def overall_rating
  @overall_rating
end

#urlObject

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

.allObject



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_sentimentObject



55
56
57
# File 'lib/shopify_app_reviews/shopify_app.rb', line 55

def overall_sentiment
  set_sentiment(self.overall_rating)
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(rating_type)
  sentiment = "Unknown"
  if rating_type.is_a?(String)
    rating = rating_type.split(" ").first
    rating = rating.to_f
  else
    rating = rating_type
  end
  sentiment = "terrible (#{rating}/5)".colorize(:red) if rating.between?(0.00,0.999)
  sentiment = "really bad (#{rating}/5)".colorize(:red) if rating.between?(1.00,1.999)
  sentiment = "OK at best (#{rating}/5)".colorize(:yellow) if rating.between?(2.00,2.999)
  sentiment = "good (#{rating}/5)".colorize(:yellow) if rating.between?(3.00,3.999)
  sentiment = "great (#{rating}/5)".colorize(:cyan) if rating.between?(4.00,4.499)
  sentiment = "excellent (#{rating}/5)".colorize(:cyan) if rating.between?(4.50,5.00)
  sentiment
end

#total_review_countObject



34
35
36
# File 'lib/shopify_app_reviews/shopify_app.rb', line 34

def total_review_count
  app_reviews.count
end


59
60
61
62
63
64
65
66
67
# File 'lib/shopify_app_reviews/shopify_app.rb', line 59

def trending_sentiment
  ratings_array = []
  self.app_reviews.each do |review|
    rating = review.rating.split(" ").first.to_f
    ratings_array << rating
  end
  trending_rating = ratings_array.reduce(:+) / ratings_array.size
  set_sentiment(trending_rating)
end