Class: String
Instance Method Summary collapse
-
#link_urls ⇒ String
encloses URI in text with with link tag.
-
#to_boolean ⇒ TrueClass, FalseClass
convert strings to boolean values.
-
#to_html(related_links = nil, description = nil, png_image = nil) ⇒ String
produces a html page for making web services browser friendly format of text (=string params) is preserved (e.g. line breaks) urls are marked as links.
-
#underscore ⇒ String
Converts camel-case to underscore-case (OpenTox::SuperModel -> open_tox/super_model).
- #uri? ⇒ Boolean
Instance Method Details
#link_urls ⇒ String
encloses URI in text with with link tag
41 42 43 |
# File 'lib/overwrite.rb', line 41 def link_urls self.gsub(/(?i)http(s?):\/\/[^\r\n\s']*/, '<a href="\0">\0</a>') end |
#to_boolean ⇒ TrueClass, FalseClass
convert strings to boolean values
33 34 35 36 37 |
# File 'lib/overwrite.rb', line 33 def to_boolean return true if self == true || self =~ (/(true|t|yes|y|1)$/i) return false if self == false || self.nil? || self =~ (/(false|f|no|n|0)$/i) bad_request_error "invalid value for Boolean: \"#{self}\"" end |
#to_html(related_links = nil, description = nil, png_image = nil) ⇒ String
produces a html page for making web services browser friendly format of text (=string params) is preserved (e.g. line breaks) urls are marked as links
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/overwrite.rb', line 53 def to_html(=nil, description=nil, png_image=nil ) # TODO add title as parameter title = nil #$sinatra.to($sinatra.request.env['PATH_INFO'], :full) if $sinatra html = "<html><body>" html << "<title>"+title+"</title>" if title #html += "<img src=\""+OT_LOGO+"\"><\/img><body>" html << "<h3>Description</h3><pre><p>"+description.link_urls+"</p></pre>" if description html << "<h3>Related links</h3><pre><p>"+.link_urls+"</p></pre>" if html << "<h3>Content</h3>" if description || html << "<pre><p style=\"padding:15px; border:10px solid \#C5C1E4\">" html << "<img src=\"data:image/png;base64,#{Base64.encode64(png_image)}\">\n" if png_image html << self.link_urls html << "</p></pre></body></html>" html end |
#underscore ⇒ String
23 24 25 26 27 28 29 |
# File 'lib/overwrite.rb', line 23 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |
#uri? ⇒ Boolean
71 72 73 |
# File 'lib/overwrite.rb', line 71 def uri? URI.valid?(self) end |