Class: Shutterstock::Subscriptions

Inherits:
Array
  • Object
show all
Defined in:
lib/client/subscriptions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_data) ⇒ Subscriptions

Returns a new instance of Subscriptions.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/client/subscriptions.rb', line 4

def initialize(raw_data)
  @raw_data = raw_data

  if raw_data.kind_of? Hash
    super(@raw_data["data"].map{ |subscription| Subscription.new(subscription) })

    @total_count   = raw_data["total_count"].to_i
    @page          = raw_data["page"].to_i
  elsif raw_data.kind_of? Array
    super( @raw_data.map{ |subscription| Subscription.new(subscription) } )
  end

  self
end

Instance Attribute Details

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/client/subscriptions.rb', line 3

def page
  @page
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



3
4
5
# File 'lib/client/subscriptions.rb', line 3

def raw_data
  @raw_data
end

#search_idObject (readonly)

Returns the value of attribute search_id.



3
4
5
# File 'lib/client/subscriptions.rb', line 3

def search_id
  @search_id
end

#sort_methodObject (readonly)

Returns the value of attribute sort_method.



3
4
5
# File 'lib/client/subscriptions.rb', line 3

def sort_method
  @sort_method
end

#total_countObject (readonly)

Returns the value of attribute total_count.



3
4
5
# File 'lib/client/subscriptions.rb', line 3

def total_count
  @total_count
end

Instance Method Details

#activeObject



32
33
34
# File 'lib/client/subscriptions.rb', line 32

def active
  self.reject{|sub| sub.expired?}
end

#downloads_leftObject



24
25
26
# File 'lib/client/subscriptions.rb', line 24

def downloads_left
  self.select{|sub| sub.has_downloads_left?}
end

#expiredObject



28
29
30
# File 'lib/client/subscriptions.rb', line 28

def expired
  self.select{|sub| sub.expired?}
end

#find_subscription_for_image_size(size = nil) ⇒ Object



19
20
21
22
# File 'lib/client/subscriptions.rb', line 19

def find_subscription_for_image_size(size = nil)
  size = "huge" if !size
  self.active.select{|sub| sub.has_downloads_left? && sub.allows_image_size_download?(size)}.first
end