Class: BizRatr::Business
- Inherits:
-
Object
- Object
- BizRatr::Business
- Defined in:
- lib/bizratr/business.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#checkins ⇒ Object
Returns the value of attribute checkins.
-
#city ⇒ Object
Returns the value of attribute city.
-
#coords ⇒ Object
Returns the value of attribute coords.
-
#country ⇒ Object
Returns the value of attribute country.
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#likes ⇒ Object
Returns the value of attribute likes.
-
#name ⇒ Object
Returns the value of attribute name.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#ratings ⇒ Object
Returns the value of attribute ratings.
-
#review_counts ⇒ Object
Returns the value of attribute review_counts.
-
#state ⇒ Object
Returns the value of attribute state.
-
#twitter ⇒ Object
Returns the value of attribute twitter.
-
#users ⇒ Object
Returns the value of attribute users.
-
#zip ⇒ Object
Returns the value of attribute zip.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_categories(connector, categories) ⇒ Object
- #add_checkins(connector, checkins) ⇒ Object
- #add_id(connector, id) ⇒ Object
- #add_likes(connector, likes) ⇒ Object
- #add_rating(connector, rating) ⇒ Object
- #add_review_counts(connector, counts) ⇒ Object
- #add_users(connector, users) ⇒ Object
- #any_equal_ids?(other) ⇒ Boolean
- #distance_to(other) ⇒ Object
-
#flattened_categories ⇒ Object
Get all categories from all connectors.
-
#initialize(lat, lon, name) ⇒ Business
constructor
A new instance of Business.
- #merge(other) ⇒ Object
- #name_distance_to(other) ⇒ Object
- #rating ⇒ Object
- #to_s ⇒ Object
- #total_checkins ⇒ Object
- #total_likes ⇒ Object
- #total_reviews ⇒ Object
- #total_users ⇒ Object
Constructor Details
#initialize(lat, lon, name) ⇒ Business
Returns a new instance of Business.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/bizratr/business.rb', line 5 def initialize(lat, lon, name) @ids = {} @checkins = {} @users = {} @likes = {} @ratings = {} @review_counts = {} @categories = {} @coords = [lat, lon] @name = name end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def address @address end |
#categories ⇒ Object
Returns the value of attribute categories.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def categories @categories end |
#checkins ⇒ Object
Returns the value of attribute checkins.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def checkins @checkins end |
#city ⇒ Object
Returns the value of attribute city.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def city @city end |
#coords ⇒ Object
Returns the value of attribute coords.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def coords @coords end |
#country ⇒ Object
Returns the value of attribute country.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def country @country end |
#ids ⇒ Object
Returns the value of attribute ids.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def ids @ids end |
#likes ⇒ Object
Returns the value of attribute likes.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def likes @likes end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def name @name end |
#phone ⇒ Object
Returns the value of attribute phone.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def phone @phone end |
#ratings ⇒ Object
Returns the value of attribute ratings.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def @ratings end |
#review_counts ⇒ Object
Returns the value of attribute review_counts.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def review_counts @review_counts end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def state @state end |
#twitter ⇒ Object
Returns the value of attribute twitter.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def twitter @twitter end |
#users ⇒ Object
Returns the value of attribute users.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def users @users end |
#zip ⇒ Object
Returns the value of attribute zip.
3 4 5 |
# File 'lib/bizratr/business.rb', line 3 def zip @zip end |
Instance Method Details
#==(other) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/bizratr/business.rb', line 121 def ==(other) return false if other.nil? return true if any_equal_ids?(other) return true if @phone == other.phone and not @phone.nil? return true if distance_to(other) < 0.3 and name_distance_to(other) < 0.4 false end |
#add_categories(connector, categories) ⇒ Object
74 75 76 |
# File 'lib/bizratr/business.rb', line 74 def add_categories(connector, categories) @categories[connector] = categories end |
#add_checkins(connector, checkins) ⇒ Object
66 67 68 |
# File 'lib/bizratr/business.rb', line 66 def add_checkins(connector, checkins) @checkins[connector] = checkins end |
#add_id(connector, id) ⇒ Object
62 63 64 |
# File 'lib/bizratr/business.rb', line 62 def add_id(connector, id) @ids[connector] = id end |
#add_likes(connector, likes) ⇒ Object
83 84 85 |
# File 'lib/bizratr/business.rb', line 83 def add_likes(connector, likes) @users[connector] = likes end |
#add_rating(connector, rating) ⇒ Object
87 88 89 |
# File 'lib/bizratr/business.rb', line 87 def (connector, ) @ratings[connector] = end |
#add_review_counts(connector, counts) ⇒ Object
91 92 93 |
# File 'lib/bizratr/business.rb', line 91 def add_review_counts(connector, counts) @review_counts[connector] = counts end |
#add_users(connector, users) ⇒ Object
70 71 72 |
# File 'lib/bizratr/business.rb', line 70 def add_users(connector, users) @users[connector] = users end |
#any_equal_ids?(other) ⇒ Boolean
95 96 97 98 99 100 |
# File 'lib/bizratr/business.rb', line 95 def any_equal_ids?(other) @ids.each { |k,v| return true if other.ids[k] == v } false end |
#distance_to(other) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/bizratr/business.rb', line 102 def distance_to(other) rpd = 0.017453293 # PI/180 dlat = other.coords[0] - @coords[0] dlon = other.coords[1] - @coords[1] dlon_rad = dlon * rpd dlat_rad = dlat * rpd lat1_rad = @coords[0] * rpd lon1_rad = @coords[1] * rpd lat2_rad = other.coords[0] * rpd lon2_rad = other.coords[1] * rpd a = (Math.sin(dlat_rad/2))**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * (Math.sin(dlon_rad/2))**2 2 * Math.atan2( Math.sqrt(a), Math.sqrt(1-a)) * 3956 # 3956 is the radius of the great circle in miles end |
#flattened_categories ⇒ Object
Get all categories from all connectors.
79 80 81 |
# File 'lib/bizratr/business.rb', line 79 def flattened_categories @categories.values.flatten.map { |c| c.downcase }.uniq end |
#merge(other) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bizratr/business.rb', line 43 def merge(other) @ids = @ids.merge(other.ids) @phone ||= other.phone @address ||= other.address @state ||= other.state @country ||= other.country @zip ||= other.zip @twitter ||= other.twitter @city ||= other.city @checkins = @checkins.merge(other.checkins) @users = @users.merge(other.users) @likes = @likes.merge(other.likes) @ratings = @ratings.merge(other.) @review_counts = @review_counts.merge(other.review_counts) @coords[0] = (@coords[0].to_f + other.coords[0].to_f) / 2.0 @coords[1] = (@coords[1].to_f + other.coords[1].to_f) / 2.0 return self end |
#name_distance_to(other) ⇒ Object
116 117 118 119 |
# File 'lib/bizratr/business.rb', line 116 def name_distance_to(other) name = other.is_a?(Business) ? other.name : other Levenshtein::normalized_distance(@name, name) end |
#rating ⇒ Object
23 24 25 |
# File 'lib/bizratr/business.rb', line 23 def @ratings.values.inject(:+) / @ratings.length end |
#to_s ⇒ Object
17 18 19 20 21 |
# File 'lib/bizratr/business.rb', line 17 def to_s attrs = [:name, :phone, :address, :state, :country, :zip, :twitter, :ids, :checkins, :users, :likes, :ratings, :review_counts, :coords, :city, :categories] args = attrs.map { |k| "#{k.to_s}=#{send(k)}" }.join(", ") "<Business [#{args}]>" end |
#total_checkins ⇒ Object
35 36 37 |
# File 'lib/bizratr/business.rb', line 35 def total_checkins @checkins.values.inject { |a,b| a+b } || 0 end |
#total_likes ⇒ Object
39 40 41 |
# File 'lib/bizratr/business.rb', line 39 def total_likes @likes.values.inject { |a,b| a+b } || 0 end |
#total_reviews ⇒ Object
31 32 33 |
# File 'lib/bizratr/business.rb', line 31 def total_reviews @review_counts.values.inject { |a,b| a+b } || 0 end |
#total_users ⇒ Object
27 28 29 |
# File 'lib/bizratr/business.rb', line 27 def total_users @users.values.inject { |a,b| a+b } || 0 end |