lib/vedeu/models/line.rb in vedeu-0.2.3 vs lib/vedeu/models/line.rb in vedeu-0.2.4

- old
+ new

@@ -35,45 +35,65 @@ instance_eval(&block) end end - # Returns a collection of streams associated with this line. + # Returns an array of all the characters with formatting for this line. # # @return [Array] - def streams - @streams ||= Stream.coercer(attributes[:streams]) + # @see Vedeu::Stream + def chars + return [] if empty? + + @_chars ||= streams.map(&:chars).flatten end - private + # Returns a boolean indicating whether the line has content. + # + # @return [Boolean] + def empty? + size == 0 + end - # Convenience method to provide Presentation with a consistent interface. + # Returns the size of the content in characters without formatting. # - # @api private + # @return [Fixnum] + def size + streams.map(&:size).inject(0, :+) { |sum, x| sum += x } + end + + # Returns a collection of streams associated with this line. This method + # also has the alias_method :data, a convenience method to provide + # Presentation with a consistent interface. + # # @return [Array] - def data - streams + def streams + @streams ||= Stream.coercer(attributes[:streams]) end + alias_method :data, :streams + private + # The default values for a new instance of Line. # - # @api private # @return [Hash] def defaults { colour: {}, streams: [], style: [], parent: nil, } end - # @api private + # @param method [Symbol] The name of the method sought. + # @param args [Array] The arguments which the method was to be invoked with. + # @param block [Proc] The optional block provided to the method. # @return [] def method_missing(method, *args, &block) Vedeu.log("Line#method_missing '#{method.to_s}' (args: #{args.inspect})") - @self_before_instance_eval.send(method, *args, &block) + @self_before_instance_eval.send(method, *args, &block) if @self_before_instance_eval end end # Line end # Vedeu