Class: IrcString::Parser
- Inherits:
-
Object
- Object
- IrcString::Parser
- Defined in:
- lib/irc-string/parser.rb
Constant Summary collapse
- COLOR_CODE =
u0003
"\x03"- BOLD =
u0002
"\x02"- UNDERLINE =
u001F
"\x1f"- INVERSE =
u0016
"\x16"- CLEAR =
u000F
"\x0f"
Instance Method Summary collapse
-
#initialize(str) ⇒ Parser
constructor
A new instance of Parser.
- #to_html(class_prefix = '') ⇒ Object
- #to_plain ⇒ Object
Constructor Details
#initialize(str) ⇒ Parser
Returns a new instance of Parser.
11 12 13 14 |
# File 'lib/irc-string/parser.rb', line 11 def initialize(str) @raw = str parse end |
Instance Method Details
#to_html(class_prefix = '') ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/irc-string/parser.rb', line 20 def to_html(class_prefix = '') @parsed_strs.map do |s| if s[:style].size == 0 s[:str] else cls = [] s[:style].each do |k,v| if v.is_a? TrueClass cls << "#{class_prefix}#{k}" elsif v.is_a? FalseClass else cls << "#{class_prefix}#{k}_#{v}" end end "<span class=\"#{cls.join(' ')}\">#{s[:str]}</span>" end end.join end |
#to_plain ⇒ Object
16 17 18 |
# File 'lib/irc-string/parser.rb', line 16 def to_plain @parsed_strs.map {|s| s[:str]}.join end |