lib/vedeu/api/interface.rb in vedeu-0.1.12 vs lib/vedeu/api/interface.rb in vedeu-0.1.13

- old
+ new

@@ -3,39 +3,49 @@ InvalidWidth = Class.new(StandardError) XOutOfBounds = Class.new(StandardError) YOutOfBounds = Class.new(StandardError) module API - class Interface - def self.create(name, &block) - new(name).create(&block) + class Interface < Vedeu::Interface + def self.build(attributes = {}, &block) + new(attributes, &block).attributes end - def initialize(name) - @name = name.to_s + def self.define(attributes = {}, &block) + new(attributes).define(&block) end - def create(&block) - instance_eval(&block) if block_given? + def initialize(attributes = {}, &block) + @attributes = attributes - stored_attributes = Store.create(attributes) + if block_given? + @self_before_instance_eval = eval('self', block.binding) - interface = Vedeu::Interface.new(stored_attributes) + instance_eval(&block) + end + end + def define(&block) + instance_eval(&block) if block_given? + stored_attributes = Vedeu::Store.create(attributes) + interface = Vedeu::Interface.new(stored_attributes) Vedeu::Buffers.create(interface) - interface end - private + def line(&block) + attributes[:lines] << Line.build(&block) + end - attr_reader :name - def use(value) Vedeu.use(value) end + def colour(value) + attributes[:colour] = value + end + def cursor(value) attributes[:cursor] = value end def delay(value) @@ -72,23 +82,23 @@ def centred(value) attributes[:geometry][:centred] = value end + def style(value) + attributes[:style] = value + end + def y_out_of_bounds?(value) value < 1 || value > Terminal.height end def x_out_of_bounds?(value) value < 1 || value > Terminal.width end - def method_missing(method_name, arg, &block) - attributes[method_name] = arg - end - - def attributes - @attributes ||= { name: name, geometry: {} } + def method_missing(method, *args, &block) + @self_before_instance_eval.send(method, *args, &block) end end end end