Skip to content
Browse files

Add Images

  • Loading branch information...
1 parent de59aa3 commit 47fbf2500d34b56d012a67357c920fe526e901c6 @tylercunnion committed Jan 9, 2013
View
1 lib/crunchbase.rb
@@ -2,6 +2,7 @@
require 'crunchbase/cb_object'
require 'crunchbase/date_methods'
require 'crunchbase/array_from_list'
+require 'crunchbase/image'
require 'crunchbase/milestone'
require 'crunchbase/company'
require 'crunchbase/financial_organization'
View
2 lib/crunchbase/company.rb
@@ -40,7 +40,7 @@ def initialize(json)
@created_at = DateTime.parse(json["created_at"])
@updated_at = DateTime.parse(json["updated_at"])
@overview = json["overview"]
- @image = json["image"]
+ @image = Image.create(json["image"])
@products_list = json["products"]
@relationships_list = json["relationships"]
@competitions = json["competitions"]
View
2 lib/crunchbase/financial_organization.rb
@@ -33,7 +33,7 @@ def initialize(json)
@created_at = DateTime.parse(json["created_at"])
@updated_at = DateTime.parse(json["updated_at"])
@overview = json['overview']
- @image = json['image']
+ @image = Image.create(json['image'])
@offices = json['offices']
@relationships_list = json["relationships"]
@investments_list = json['investments']
View
36 lib/crunchbase/image.rb
@@ -0,0 +1,36 @@
+module Crunchbase
+ class Image
+
+ def self.create(hash)
+ hash ? self.new(hash) : nil
+ end
+
+ attr_reader :attribution, :sizes
+
+ def initialize(hash)
+ return nil unless hash
+ @attribution = hash['attribution']
+ @sizes = hash['available_sizes'].map{|s| ImageSize.new(s)}.sort
+ end
+ end
+
+ class ImageSize
+ include Comparable
+
+ attr_reader :height, :width, :url
+
+ def <=>(anOther)
+ pixels <=> anOther.pixels
+ end
+
+ def initialize(ary)
+ @width = ary[0][0]
+ @height = ary[0][1]
+ @url = ary[1]
+ end
+
+ def pixels
+ return @width * @height
+ end
+ end
+end
View
3 lib/crunchbase/person.rb
@@ -10,7 +10,7 @@ class Person < CB_Object
attr_reader :first_name, :last_name, :permalink, :crunchbase_url,
:homepage_url, :birthplace, :twitter_username, :blog_url, :blog_feed_url,
:affiliation_name, :created_at, :updated_at, :overview, :created_at,
- :updated_at, :overview, :video_embeds, :external_links, :web_presences
+ :updated_at, :image, :video_embeds, :external_links, :web_presences
def self.find(first_name, last_name)
get(API.permalink({first_name: first_name, last_name: last_name}, "people")["permalink"])
@@ -35,6 +35,7 @@ def initialize(json)
@created_at = DateTime.parse(json["created_at"])
@updated_at = DateTime.parse(json["updated_at"])
@overview = json["overview"]
+ @image = Image.create(json["image"])
@relationships_list = json["relationships"]
@investments_list = json["investments"]
@milestones_list = json["milestones"]
View
2 lib/crunchbase/product.rb
@@ -34,7 +34,7 @@ def initialize(json)
@created_at = DateTime.parse(json['created_at'])
@updated_at = DateTime.parse(json['updated_at'])
@overview = json['overview']
- @image = json['image']
+ @image = Image.create(json["image"])
@company_permalink = json['company']['permalink']
@company_name = json['company']['name']
@milestones_list = json['milestones']
View
2 lib/crunchbase/service_provider.rb
@@ -20,7 +20,7 @@ def initialize(json)
@created_at = DateTime.parse(json["created_at"])
@updated_at = DateTime.parse(json["updated_at"])
@overview = json["overview"]
- @image = json["image"]
+ @image = Image.create(json["image"])
@offices = json["offices"]
@providerships_list = json["providerships"]
@external_links = json["external_links"]

0 comments on commit 47fbf25

Please sign in to comment.
Something went wrong with that request. Please try again.