Module: YeshuaCrm::Liquid::Filters::Base
- Includes:
- MoneyHelper
- Defined in:
- lib/yeshua_crm/liquid/filters/base.rb
Instance Method Summary
collapse
#all_currencies, #collection_for_currencies_select, #deal_currency_icon, #object_price, #price_to_currency, #prices_collection_by_currency
Instance Method Details
#attachment(input, file_name) ⇒ Object
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 106
def attachment(input, file_name)
if input.respond_to?(:attachments)
if input.attachments.is_a?(Hash)
attachment = input.attachments[file_name]
else
attachment = input.attachments.detect{|a| a.file_name == file_name}
end
AttachmentDrop.new attachment if attachment
end
end
|
#call_method(input, method_name) ⇒ Object
94
95
96
97
98
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 94
def call_method(input, method_name)
if input.respond_to?(method_name)
input.method(method_name).call
end
end
|
#ceil(input) ⇒ Object
82
83
84
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 82
def ceil(input)
to_number(input).ceil.to_i
end
|
#currency(input, currency_code = 'BRL') ⇒ Object
90
91
92
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 90
def currency(input, currency_code = 'BRL')
price_to_currency(input, currency_code, :converted => false)
end
|
#custom_field(input, field_name) ⇒ Object
100
101
102
103
104
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 100
def custom_field(input, field_name)
if input.respond_to?(:custom_fields)
input.custom_fields[field_name]
end
end
|
#dasherize(input) ⇒ Object
25
26
27
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 25
def dasherize(input)
input.to_s.gsub(' ', '-').gsub('/', '-').dasherize
end
|
#date_range(input, distanse) ⇒ Object
example:
{{ today | date_range: '2015-12-12' }}
59
60
61
62
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 59
def date_range(input, distanse)
return '' if input.nil?
(input.to_date - distanse.to_date).to_i rescue 'Invalid date'
end
|
#default(input, value) ⇒ Object
17
18
19
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 17
def default(input, value)
input.blank? ? value : input
end
|
#encode(input) ⇒ Object
example:
{{ "http:://www.example.com?key=hello world" | encode }}
=> http%3A%3A%2F%2Fwww.example.com%3Fkey%3Dhello+world
45
46
47
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 45
def encode(input)
::Rack::Utils.escape(input)
end
|
#floor(input) ⇒ Object
86
87
88
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 86
def floor(input)
to_number(input).floor.to_i
end
|
#md5(input) ⇒ Object
37
38
39
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 37
def md5(input)
Digest::MD5.hexdigest(input) unless input.blank?
end
|
#modulo(input, operand) ⇒ Object
71
72
73
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 71
def modulo(input, operand)
apply_operation(input, operand, :%)
end
|
#plus_days(input, distanse) ⇒ Object
example:
{{ today | plus_days: 2 }}
51
52
53
54
55
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 51
def plus_days(input, distanse)
return '' if input.nil?
days = distanse.to_i
input.to_date + days.days rescue 'Invalid date'
end
|
#random(input) ⇒ Object
33
34
35
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 33
def random(input)
rand(input.to_i)
end
|
#round(input, n = 0) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 75
def round(input, n = 0)
result = to_number(input).round(to_number(n))
result = result.to_f if result.is_a?(BigDecimal)
result = result.to_i if n == 0
result
end
|
#shuffle(array) ⇒ Object
29
30
31
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 29
def shuffle(array)
array.to_a.shuffle
end
|
#textilize(input) ⇒ Object
13
14
15
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 13
def textilize(input)
RedCloth3.new(input).to_html
end
|
#underscore(input) ⇒ Object
21
22
23
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 21
def underscore(input)
input.to_s.gsub(' ', '_').gsub('/', '_').underscore
end
|
#utc(input) ⇒ Object
66
67
68
69
|
# File 'lib/yeshua_crm/liquid/filters/base.rb', line 66
def utc(input)
return '' if input.nil?
input.to_time.utc rescue 'Invalid date'
end
|