Class: Massaji::Spa
- Inherits:
-
Object
- Object
- Massaji::Spa
- Defined in:
- lib/massaji.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text, tag = "p") ⇒ Spa
constructor
Clean up some text by replacing characters.
-
#insert_html(text) ⇒ Object
Replaces certain escape characters with html tags.
-
#wrap(text, tag) ⇒ Object
Once the text has finished going through a new Spa it needs to put its “clothes” back on, or attach original html tags.
Constructor Details
#initialize(text, tag = "p") ⇒ Spa
Clean up some text by replacing characters.
text - The text coming in that is currently “full of knots”, or
bad text.
tag - Optional tag to pass in, defaults to paragraph tag.
Examples
Massaji::Spa.new("children\342\200\231s")
# => "children's"
Returns the text with appropriate substitutions made.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/massaji.rb', line 19 def initialize(text, tag="p") text.gsub!(/\\342\\200(?:\\234|\\235)/,'"') text.gsub!(/\\342\\200(?:\\230|\\231)/,"'") text.gsub!(/\\342\\200\\223/,"-") text.gsub!(/\\342\\200\\224/,"--") text.gsub!(/\\342\\200\\246/,"...") # not sure what these are, make empty for now text.gsub!(/\\342\\200\\242/,"") text.gsub!(/\\342\\200\\250/,"") text.gsub!(/\\342\\204\\242/,"") text.gsub!(/\\303\\251/,"") # e in cafe? text.gsub!(/\\303\\261/,"") insert_html(text) text = wrap(text, tag) @text = text end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
5 6 7 |
# File 'lib/massaji.rb', line 5 def text @text end |
Instance Method Details
#insert_html(text) ⇒ Object
Replaces certain escape characters with html tags
text - Text that needs escaped text replaced with html
Example
insert_html("The children's house \r\n needs cleaned")
# => "The children's house <br/><br/> needs cleaned")
Returns text with appropriate html tags in place.
67 68 69 70 71 72 73 74 |
# File 'lib/massaji.rb', line 67 def insert_html(text) text.gsub!("\\r\\n", "<br/><br/>") text.gsub!("\\n\\n", "<br/><br/>") text.gsub!("\\n", "<br/><br/>") text.gsub!("\\t", "-") text end |
#wrap(text, tag) ⇒ Object
Once the text has finished going through a new Spa it needs to put its “clothes” back on, or attach original html tags.
text - Text being passed in that’s been cleaned up. tag - The type of tag that needs to wrap the text.
Example
wrap("Children's", "p")
# => <p>Children's</p>
Returns the cleaned up text with the appropriate tags around it.
53 54 55 |
# File 'lib/massaji.rb', line 53 def wrap(text, tag) wrapped_text = "<#{tag}>"+text+"</#{tag}>" end |