lighttroupe/luz-next

View on GitHub
engine/user_object_settings/user_object_setting_directors.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'user_object_setting'

class UserObjectSettingDirectors < UserObjectSetting
    #
    # API for plugins
    #
    def one(index=0)
        list = get_directors
        return if list.empty?        # NOTE: doesn't yield

        selection = list[index % list.size]        # NOTE: wraps at both edges
        yield selection if block_given?
        selection
    end

    def count
        get_directors.size
    end

    def each
        get_directors.each { |director| yield director }
    end

    def all
        yield get_directors
    end

private

    def get_directors
        @directors ||= all_directors.dup
    end

    def all_directors
        $engine.project.directors
    end
end