Module: BlackStack::Strings::Encoding
- Defined in:
- lib/functions.rb
Overview
Encoding: Make a string nice to be shown into an HTML string.
Class Method Summary collapse
-
.encode_exception(e, include_backtrace = true) ⇒ Object
Generates a description string from an exception object.
- .encode_guid(s) ⇒ Object
-
.encode_html(s) ⇒ Object
Escape the string to be shown into an HTML screen.
- .encode_javascript(s) ⇒ Object
-
.encode_period(period, units) ⇒ Object
Returns a string with a description of a period of time, to be shown in the screen.
-
.encode_string(s) ⇒ Object
Then it makes it compatible with UTF-8.
Class Method Details
.encode_exception(e, include_backtrace = true) ⇒ Object
Generates a description string from an exception object. Eescapes the string to be shown into an HTML screen. Makes it compatible with UTF-8. More details here: bitbucket.org/leandro_sardi/blackstack/issues/961
592 593 594 595 596 597 598 599 600 |
# File 'lib/functions.rb', line 592 def self.encode_exception(e, include_backtrace=true) ret = encode_html(e.to_s) if (include_backtrace == true) e.backtrace.each { |s| ret += "<br/>" + encode_html(s) } # e.backtrace.each end # if ret end |
.encode_guid(s) ⇒ Object
622 623 624 |
# File 'lib/functions.rb', line 622 def self.encode_guid(s) return s.gsub('{',"").gsub('}',"").downcase end |
.encode_html(s) ⇒ Object
Escape the string to be shown into an HTML screen. Then it makes it compatible with UTF-8. More details here: bitbucket.org/leandro_sardi/blackstack/issues/961
584 585 586 |
# File 'lib/functions.rb', line 584 def self.encode_html(s) encode_string(CGI.escapeHTML(s.to_s)) end |
.encode_javascript(s) ⇒ Object
627 628 629 |
# File 'lib/functions.rb', line 627 def self.encode_javascript(s) s.to_s.gsub("'", "\\\\'").gsub("\r", "' + String.fromCharCode(13) + '").gsub("\n", "' + String.fromCharCode(10) + '") end |
.encode_period(period, units) ⇒ Object
Returns a string with a description of a period of time, to be shown in the screen. period: it may be ‘H’, ‘D’, ‘W’, ‘M’, ‘Y’
units: it is a positive integer
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
# File 'lib/functions.rb', line 605 def self.encode_period(period, units) s = "Last " s += units.to_i.to_s + " " if units.to_i > 1 s += "Hours" if period.upcase == "H" && units.to_i != 1 s += "Days" if period.upcase == "D" && units.to_i != 1 s += "Weeks" if period.upcase == "W" && units.to_i != 1 s += "Months" if period.upcase == "M" && units.to_i != 1 s += "Years" if period.upcase == "Y" && units.to_i != 1 s += "Hour" if period.upcase == "H" && units.to_i == 1 s += "Day" if period.upcase == "D" && units.to_i == 1 s += "Week" if period.upcase == "W" && units.to_i == 1 s += "Month" if period.upcase == "M" && units.to_i == 1 s += "Year" if period.upcase == "Y" && units.to_i == 1 s end |
.encode_string(s) ⇒ Object
Then it makes it compatible with UTF-8. More details here: bitbucket.org/leandro_sardi/blackstack/issues/961
577 578 579 |
# File 'lib/functions.rb', line 577 def self.encode_string(s) s.encode("UTF-8") end |