Skip to content

Commit

Permalink
Fixed issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhellsten committed Dec 2, 2011
1 parent dac9f6b commit 9c41b7f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/panoramio.rb
Expand Up @@ -74,14 +74,16 @@ def all_photos(options = {})
end end
end end


# TODO document
#
# Get even more photos from Panoramio. Divide area using :part_size in options. # Get even more photos from Panoramio. Divide area using :part_size in options.
# #
# :call-seq: # :call-seq:
# Panoramio.photos_adv( Hash options ) = > Hash with photos and calculated data # Panoramio.photos_adv( Hash options ) = > Hash with photos and calculated data
def photos_adv(options = {}) def photos_adv(options = {})
# not enough data # not enough data
return [] if options[:minx].nil? or options[:maxx].nil? or options[:miny].nil? or options[:maxy].nil? return nil unless options[:minx] || options[:maxx] || options[:miny] || options[:maxy]
return photos(options) if options[:part_size].nil? return photos(options) unless options[:part_size]


# start creating parts # start creating parts
x_length = options[:maxx] - options[:minx] x_length = options[:maxx] - options[:minx]
Expand All @@ -97,14 +99,12 @@ def photos_adv(options = {})
output = [] output = []
(0...(x_partial_count)).each do |x| (0...(x_partial_count)).each do |x|
(0...(y_partial_count)).each do |y| (0...(y_partial_count)).each do |y|
h = options.clone.merge( h = options.clone.merge({
{ :minx => options[:minx] + x * x_precised_part_size,
:minx => options[:minx] + x * x_precised_part_size, :maxx => options[:minx] + (1 + x) * x_precised_part_size,
:maxx => options[:minx] + (1 + x) * x_precised_part_size, :miny => options[:miny] + y * y_precised_part_size,
:miny => options[:miny] + y * y_precised_part_size, :maxy => options[:miny] + (1 + y) * y_precised_part_size,
:maxy => options[:miny] + (1 + y) * y_precised_part_size, })
}
)
output += photos_all(h) output += photos_all(h)
end end
end end
Expand Down Expand Up @@ -133,7 +133,6 @@ def to_uri(options)
end end


def to_photos(json) def to_photos(json)
# fix for 'no photos'
return nil if json['photos'].first.nil? return nil if json['photos'].first.nil?
# issues with redefinition # issues with redefinition
struct = defined?(Struct::Photo) ? Struct::Photo : Struct.new('Photo', *json['photos'].first.keys) struct = defined?(Struct::Photo) ? Struct::Photo : Struct.new('Photo', *json['photos'].first.keys)
Expand Down

0 comments on commit 9c41b7f

Please sign in to comment.