Module: DefaultFilters
- Defined in:
- lib/h2o/filters/default.rb
Instance Method Summary collapse
- #capitalize(string) ⇒ Object
- #contain(object, item) ⇒ Object
- #escape(string, attribute = false) ⇒ Object
- #first(list) ⇒ Object
-
#join(list, delimiter = ', ') ⇒ Object
Array Filters.
- #last(list) ⇒ Object
- #lower(string) ⇒ Object
-
#upper(string) ⇒ Object
String filters.
Instance Method Details
#capitalize(string) ⇒ Object
12 13 14 |
# File 'lib/h2o/filters/default.rb', line 12 def capitalize string string.to_s.capitalize end |
#contain(object, item) ⇒ Object
45 46 47 |
# File 'lib/h2o/filters/default.rb', line 45 def contain(object, item) object.include?(item) end |
#escape(string, attribute = false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/h2o/filters/default.rb', line 16 def escape string, attribute=false string = string.dup.to_s { '&' => '&', '>' => '>', '<' => '<' }.each do |v, k| string.tr!(v, k) end string.gsub!(/"/, '"') if attribute string end |
#first(list) ⇒ Object
37 38 39 |
# File 'lib/h2o/filters/default.rb', line 37 def first(list) list.first end |
#join(list, delimiter = ', ') ⇒ Object
Array Filters
33 34 35 |
# File 'lib/h2o/filters/default.rb', line 33 def join(list, delimiter=', ') list.join(delimiter) end |
#last(list) ⇒ Object
41 42 43 |
# File 'lib/h2o/filters/default.rb', line 41 def last(list) list.last end |
#lower(string) ⇒ Object
8 9 10 |
# File 'lib/h2o/filters/default.rb', line 8 def lower string string.to_s.downcase end |
#upper(string) ⇒ Object
String filters
4 5 6 |
# File 'lib/h2o/filters/default.rb', line 4 def upper string string.to_s.upcase end |