lib/vedeu/models/stream.rb in vedeu-0.1.10 vs lib/vedeu/models/stream.rb in vedeu-0.1.12

- old
+ new

@@ -1,15 +1,35 @@ module Vedeu class Stream - include Virtus.model + def initialize(attributes = {}) + @attributes = attributes + end - attribute :colour, Colour, default: Colour.new - attribute :style, Style, default: '' - attribute :text, String, default: '' - attribute :width, Integer - attribute :align, Symbol, default: :left + def attributes + defaults.merge!(@attributes) + end + def colour + @colour ||= Colour.new(attributes[:colour]) + end + + def style + @style ||= Attributes.coerce_styles(attributes[:style]) + end + + def text + @text ||= attributes[:text] + end + + def width + @width ||= attributes[:width] + end + + def align + @align ||= attributes[:align] + end + def to_s [ colour, style, data ].join end private @@ -26,8 +46,18 @@ end end def width? !!width + end + + def defaults + { + colour: {}, + style: '', + text: '', + width: nil, + align: :left + } end end end