Sha256: 04e558909bccae36c190ec3f80118c2b0811c05e410e2c8962c6131431ef598c

Contents?: true

Size: 886 Bytes

Versions: 1

Compression:

Stored size: 886 Bytes

Contents

module Vedeu
  module API
    class Base
      def self.build(attributes = {}, &block)
        new(attributes, &block).build
      end

      def initialize(attributes, &block)
        @attributes = attributes

        self.instance_eval(&block) if block_given?
      end

      def colour(*args)
        if args.is_a?(Array) && args.size == 2
          attributes[:colour] = { background: args.first, foreground: args.last }

        elsif args.is_a?(Array) && args.size == 1 && args.first.is_a?(Hash)
          attributes[:colour] = args.first

        else
          attributes[:colour] = {}

        end
      end

      def style(values = [], &block)
        if block_given?
          attributes[:streams] << API::Stream.build({ style: [values] }, &block)
        else
          [values].flatten.each { |value| attributes[:style] << value }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.1.5 lib/vedeu/api/base.rb