lib/vedeu/models/stream.rb in vedeu-0.1.18 vs lib/vedeu/models/stream.rb in vedeu-0.1.19
- old
+ new
@@ -1,40 +1,43 @@
module Vedeu
+
+ # A Stream can represent a character or collection of characters as part of a
+ # {Vedeu::Line} which you wish to colour and style independently of the other
+ # characters in that line.
class Stream
+
include Coercions
include Presentation
- attr_reader :attributes, :align, :text, :width
+ attr_reader :attributes, :align, :text, :width, :parent
# @param attributes [Hash]
# @param block [Proc]
# @return [Hash]
def self.build(attributes = {}, &block)
new(attributes, &block).attributes
end
+ # Returns a new instance of Stream.
+ #
# @param attributes [Hash]
# @param block [Proc]
# @return [Stream]
def initialize(attributes = {}, &block)
@attributes = defaults.merge!(attributes)
@align = @attributes[:align]
@text = @attributes[:text]
@width = @attributes[:width]
+ @parent = @attributes[:parent]
if block_given?
@self_before_instance_eval = eval('self', block.binding)
instance_eval(&block)
end
end
- # @return [String]
- def to_s
- [ colour, style, data ].join
- end
-
private
# @api private
# @return [String]
def data
@@ -55,18 +58,21 @@
# @return [TrueClass|FalseClass]
def width?
!!width
end
+ # The default values for a new instance of Stream.
+ #
# @api private
# @return [Hash]
def defaults
{
colour: {},
style: [],
text: '',
width: nil,
- align: :left
+ align: :left,
+ parent: nil,
}
end
# @api private
# @return []