Sha256: 437c62a1ef66e2c8fc95bbafd601d94c8bfb1864732aed69742a82ae87d6aa5f

Contents?: true

Size: 1.04 KB

Versions: 18

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require_relative './collector/game'

class Collector
  include Arstotzka

  MALE = 'male'
  FEMALE = 'female'

  attr_reader :hash

  expose :full_name, :age, path: :person, json: :hash
  expose :gender, path: :person, type: :gender, cached: true, json: :hash
  expose :car_names, flatten: true, compact: false, json: :hash,
                     default: 'MissingName',
                     full_path: 'collections.cars.units.nick_name'
  expose :finished_games, json: :hash,
                          flatten: true, klass: Collector::Game,
                          after: :filter_finished, compact: true,
                          full_path: 'collections.games.titles'

  def initialize(hash = {})
    @hash = hash
  end

  private

  def filter_finished(games)
    games.select(&:finished?)
  end
end

module Arstotzka
  module TypeCast
    def to_gender(value)
      case value
      when 'man'
        Collector::MALE
      when 'woman'
        Collector::FEMALE
      else
        raise 'invalid gender'
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
arstotzka-1.6.2 spec/support/models/collector.rb
arstotzka-1.6.1 spec/support/models/collector.rb
arstotzka-1.6.0 spec/support/models/collector.rb
arstotzka-1.5.0 spec/support/models/collector.rb
arstotzka-1.4.4 spec/support/models/collector.rb
arstotzka-1.4.3 spec/support/models/collector.rb
arstotzka-1.4.2 spec/support/models/collector.rb
arstotzka-1.4.1 spec/support/models/collector.rb
arstotzka-1.4.0 spec/support/models/collector.rb
arstotzka-1.3.2 spec/support/models/collector.rb
arstotzka-1.3.1 spec/support/models/collector.rb
arstotzka-1.3.0 spec/support/models/collector.rb
arstotzka-1.2.4 spec/support/models/collector.rb
arstotzka-1.2.3 spec/support/models/collector.rb
arstotzka-1.2.2 spec/support/models/collector.rb
arstotzka-1.2.1 spec/support/models/collector.rb
arstotzka-1.2.0 spec/support/models/collector.rb
arstotzka-1.1.0 spec/support/models/collector.rb