class TRecs::Frame
Attributes
content[RW]
format[RW]
Public Class Methods
new(opts={})
click to toggle source
# File lib/trecs/frame.rb, line 6 def initialize(opts={}) opts = opts.is_a?(Hash) ? opts : {content: opts} @content = opts.fetch(:content) { "" } @format = opts[:format] || "raw" end
Public Instance Methods
==(other)
click to toggle source
# File lib/trecs/frame.rb, line 39 def ==(other) other = Frame(other) to_s == other.to_s && format == other.format end
each()
click to toggle source
# File lib/trecs/frame.rb, line 23 def each content.each_line end
height()
click to toggle source
# File lib/trecs/frame.rb, line 19 def height raw_text.lines.count end
raw_text()
click to toggle source
# File lib/trecs/frame.rb, line 45 def raw_text @raw_text = if format == "html" content.split("\n").join("\\n").gsub(/<style>.+<\/style>/, "").gsub("\\n", "\n").gsub(%r{</?[^>]+?>}, '') else content end end
to_h()
click to toggle source
# File lib/trecs/frame.rb, line 32 def to_h { content: content, format: format } end
to_s()
click to toggle source
# File lib/trecs/frame.rb, line 27 def to_s content end
Also aliased as: to_str
width()
click to toggle source
# File lib/trecs/frame.rb, line 12 def width widths = raw_text.each_line.map { |line| line.chomp.size } widths.max || 0 end