Sha256: 78e376f0a0d191eccf7e14a9d9396426551ed97daa03432b5991280d0906e46f

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

module Apprank
  class App

    attr_accessor :name, :icon_urls, :summary, :price, :content_type, :rights, :title,
      :link, :itunes_url, :itunes_id, :bundle_id, :artist, :artist, :category, :release_date

    alias_method :developer, :artist

    def initialize(hash)
      @name = hash["im:name"]["label"]
      @icon_urls = {}
      hash["im:image"].each do |image|
        height =
          if image["attributes"]["height"] == '53'
            :small
          elsif image["attributes"]["height"] == '75'
            :medium
          else
            :large
          end
        @icon_urls[height] = image["label"]
      end
      @summary = hash["summary"]["label"]
      @price = {
        :amount => hash["im:price"]["attributes"]["amount"].to_f,
        :currency => hash["im:price"]["attributes"]["currency"]
      }
      @content_type = hash["rights"]["contentType"]
      @rights = hash["rights"]["label"]
      @title = hash["title"]["label"]

      link = hash["link"]
      if link["attributes"]["title"] == "Preview"
        @preview = link["attributes"]["href"]
      else
        @link = link["attributes"]["href"]
      end

      @itunes_url = hash["id"]["label"]
      @itunes_id = hash["id"]['attributes']['im:id']
      @bundle_id = hash["id"]['attributes']['im:bundleId']

      @artist = {
        :name => hash["im:artist"]["label"],
        :url => hash["im:artist"]["attributes"]["href"]
      }
      @category = {
        :name => hash["category"]["attributes"]["term"],
        :url => hash["category"]["attributes"]["scheme"]
      }
      @release_date = Time.parse(hash["im:releaseDate"]["label"])
    end

    def itunes_id
      self.itunes_url.split(/\//).last.split(/\?/).first.gsub(/[^\d]/,'')
    end

    def is_free?
      self.price[:amount].zero?
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apprank-1.0.0 lib/apprank/app.rb