Sha256: 18b50a8251591ec228d9b7b7dfb43f77a817036a3cd2b24f914130788d794aec

Contents?: true

Size: 777 Bytes

Versions: 3

Compression:

Stored size: 777 Bytes

Contents

module FakerMaker
  class Attribute
    attr_reader :name, :block, :translation

    def initialize name, options={}, block
      assert_valid_options options
      @name = name
      @block = block
      @cardinality = options[:has] || 1
      @translation = options[:json]
      @array = options[:array] == true 
    end

    def array?
      forced_array? || @array
    end

    def cardinality
      if @cardinality.is_a? Range
        rand( @cardinality ) 
      else
        @cardinality
      end
    end

    def translation?
      ! @translation.blank?
    end

    private 

    def forced_array?
      @cardinality.is_a?( Range ) || @cardinality > 1
    end

    def assert_valid_options options
      options.assert_valid_keys :has, :array, :json
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
faker_maker-1.0.0 lib/faker_maker/attribute.rb
faker_maker-0.7.1 lib/faker_maker/attribute.rb
faker_maker-0.7.0 lib/faker_maker/attribute.rb