Sha256: f9186e782e4cad621e5b6ef4ebb07290c500eab035e715a6f634e0ef6de3b829

Contents?: true

Size: 1.68 KB

Versions: 248

Compression:

Stored size: 1.68 KB

Contents

module Spaceship
  module Tunes
    class Availability < TunesBase
      # @return (Bool) Are future territories included?
      attr_accessor :include_future_territories

      # @return (Array of Spaceship::Tunes::Territory objects) A list of the territories
      attr_accessor :territories

      attr_mapping(
        'theWorld' => :include_future_territories
      )

      class << self
        # Create a new object based on a hash.
        # This is used to create a new object based on the server response.
        def factory(attrs)
          obj = self.new(attrs)
          obj.unfold_territories(attrs['countries'])
          return obj
        end

        # Create a new object based on a set of territories.
        # @param territories (Array of String or Spaceship::Tunes::Territory objects): A list of the territories
        # @param params (Hash): Optional parameters (include_future_territories (Bool, default: true) Are future territories included?)
        def from_territories(territories = [], params = {})
          obj = self.new
          # Detect if the territories attribute is an array of Strings and convert to Territories
          obj.territories =
            if territories[0].kind_of?(String)
              territories.map { |territory| Spaceship::Tunes::Territory.from_code(territory) }
            else
              territories
            end
          obj.include_future_territories = params.fetch(:include_future_territories, true)
          return obj
        end
      end

      def unfold_territories(attrs)
        unfolded_territories = attrs.map { |info| Territory.new(info) }
        instance_variable_set(:@territories, unfolded_territories)
      end
    end
  end
end

Version data entries

248 entries across 248 versions & 1 rubygems

Version Path
fastlane-2.52.0.beta.20170808010002 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.51.0 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.51.0.beta.20170807010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.51.0.beta.20170806010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.51.0.beta.20170805010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.51.0.beta.20170804010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.51.0.beta.20170803010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.50.1 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.51.0.beta.20170802010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.51.0.beta.20170801010002 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.50.0 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.50.0.beta.20170731010002 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.50.0.beta.20170730010002 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.50.0.beta.20170729010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.50.0.beta.20170728010002 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.50.0.beta.20170727010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.49.0 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.49.0.beta.20170726010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.49.0.beta.20170725010003 spaceship/lib/spaceship/tunes/availability.rb
fastlane-2.48.0 spaceship/lib/spaceship/tunes/availability.rb