Sha256: a39b9a83e8dd53e5bb2b1f048cf4470cc7b12dc66e243b0772a4b26221a1e2bf

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'hatsrank/listing'
require 'hatsrank/item'

module Hatsrank
  class ListingParser
    def initialize listing_hash, asset_hash
      @listing_hash = listing_hash
      @asset_hash = asset_hash
    end

    def listings
      listings = @listing_hash.values.map do |listing|

        l = Listing.new
        l.listing_id = listing['listingid']
        l.price      = listing['price']
        l.currency   = listing['currencyid']

        asset_info    = listing['asset']
        asset_id      = asset_info['id']
        asset_app     = asset_info['appid']
        asset_context = asset_info['contextid']

        asset = @asset_hash[asset_app.to_s][asset_context.to_s][asset_id.to_s]

        item = Item.new
        item.name = asset['name']

        if asset['descriptions']
          asset['descriptions'].each do |description|
            d        = Description.new
            d.type   = description['type']
            d.value  = description['value']
            d.color  = description['color']
            item.descriptions << d
          end
        end

        l.item = item
        l
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hatsrank-0.0.1 lib/hatsrank/listing_parser.rb