Sha256: 4107f2d7446af1e119966f6769f11da8a48c8294c1af7fe45c7a1c7f49441135

Contents?: true

Size: 1.33 KB

Versions: 10

Compression:

Stored size: 1.33 KB

Contents

module Neutral
  module Icons
    class Collection
      DEFAULTS = {
        thumbs: {
          positive: 'fa-thumbs-o-up',
          negative: 'fa-thumbs-o-down',
          remove: 'fa-times'
          },
        operations: {
          positive: 'fa-plus-circle',
          negative: 'fa-minus-circle',
          remove: 'fa-times'
        }
      }.freeze

      def initialize
        DEFAULTS.each do |name, definitions|
          define!(name, definitions)
        end
      end

      def add(set)
        already_defined(set.name) if exists? set.name
        define!(set.name, set.definitions)
      end

      private

      class Definitions < Struct.new(:positive, :negative, :remove)
        [:positive=, :negative=, :remove=].each { |method| undef_method method }
      end

      def define!(name, definitions)
        class_eval do
          define_method(name) do
            Definitions.new definitions[:positive], definitions[:negative], definitions[:remove]
          end
        end
      end

      def exists?(name)
        respond_to? name
      end

      def already_defined(name)
        raise Neutral::Errors::AlreadyDefinedIconSet, "Icon set '#{name}' is already defined"
      end

      def method_missing(name)
        raise Neutral::Errors::UndefinedIconSet, "Icon set '#{name}' is not defined"
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
neutral-0.0.10 lib/neutral/icons/collection.rb
neutral-0.0.9 lib/neutral/icons/collection.rb
neutral-0.0.8 lib/neutral/icons/collection.rb
neutral-0.0.7 lib/neutral/icons/collection.rb
neutral-0.0.6 lib/neutral/icons/collection.rb
neutral-0.0.5 lib/neutral/icons/collection.rb
neutral-0.0.4 lib/neutral/icons/collection.rb
neutral-0.0.3 lib/neutral/icons/collection.rb
neutral-0.0.2 lib/neutral/icons/collection.rb
neutral-0.0.1 lib/neutral/icons/collection.rb