class Omniboard::StyledTextElement
Represents a little bit of styled text, complete with styling values and the like. Make me big, make me small, make me italic, just don't make me work weekends.
Attributes
styles[RW]
Applied values
text[RW]
The actual text
Public Class Methods
new(string)
click to toggle source
Initialize from a string
# File lib/omniboard/styled_text_element.rb, line 11 def initialize(string) @text = string[/<lit>(.*?)<\/lit>/,1] || "" @styles = {} raw_styles = string[/<style>(.*?)<\/style>/,1] if raw_styles raw_styles.scan(/<value key="(.*?)">(.*?)<\/value>/).each do |match| @styles[match[0]] = match[1] end end end
Public Instance Methods
[](k)
click to toggle source
# File lib/omniboard/styled_text_element.rb, line 23 def [] k @styles[k] end
to_html()
click to toggle source
# File lib/omniboard/styled_text_element.rb, line 27 def to_html surrounds = [] surrounds << "i" if self["font-italic"] == "yes" surrounds << "b" if self["font-weight"].to_i > 7 surrounds << "u" if self["underline-style"] == "single" tag(text, *surrounds) end
Private Instance Methods
tag(text, *tags)
click to toggle source
# File lib/omniboard/styled_text_element.rb, line 37 def tag(text, *tags) tags.map{|t| "<#{t}>"}.join("") + text + tags.reverse.map{|t| "</#{t}>"}.join("") end