Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

a Snail#to_html method

  • Loading branch information...
commit ada04703d22523ae27f6d1393183c6121e4cf132 1 parent 3fad5c8
@cainlevy cainlevy authored
Showing with 14 additions and 0 deletions.
  1. +4 −0 lib/snail.rb
  2. +10 −0 test/snail_test.rb
View
4 lib/snail.rb
@@ -33,6 +33,10 @@ def to_s
[name, line_1, line_2, city_line, country_line].select{|line| !(line.nil? or line.empty?)}.join("\n")
end
+ def to_html
+ "<address>#{to_s.gsub("\n", '<br />')}</address>"
+ end
+
# this method will get much larger. completeness is out of my scope at this time.
# currently it's based on the sampling of city line formats from frank's compulsive guide.
def city_line
View
10 test/snail_test.rb
@@ -77,6 +77,16 @@ def setup
s = Snail.new(@ca.merge(:country => "Unknown"))
assert_raises Snail::UnknownCountryError do s.to_s end
end
+
+ test "to_s" do
+ s = Snail.new(@ca)
+ assert_equal "John Doe\n12345 5th St\nSomewheres NY 12345\nCANADA", s.to_s
+ end
+
+ test "to_html" do
+ s = Snail.new(@ca)
+ assert_equal "<address>John Doe<br />12345 5th St<br />Somewheres NY 12345<br />CANADA</address>", s.to_html
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.