Class: Omniboard::StyledTextElement
- Inherits:
-
Object
- Object
- Omniboard::StyledTextElement
- Defined in:
- lib/omniboard/styled_text_element.rb
Overview
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.
Instance Attribute Summary collapse
-
#styles ⇒ Object
Applied values.
-
#text ⇒ Object
The actual text.
Instance Method Summary collapse
- #[](k) ⇒ Object
-
#initialize(string) ⇒ StyledTextElement
constructor
Initialize from a string.
- #to_html ⇒ Object
Constructor Details
#initialize(string) ⇒ StyledTextElement
Initialize from a string
11 12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#styles ⇒ Object
Applied values
8 9 10 |
# File 'lib/omniboard/styled_text_element.rb', line 8 def styles @styles end |
#text ⇒ Object
The actual text
5 6 7 |
# File 'lib/omniboard/styled_text_element.rb', line 5 def text @text end |
Instance Method Details
#[](k) ⇒ Object
23 24 25 |
# File 'lib/omniboard/styled_text_element.rb', line 23 def [] k @styles[k] end |
#to_html ⇒ Object
27 28 29 30 31 32 33 34 |
# 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 |