Class: Releaf::Settings::NormalizeValue

Inherits:
Object
  • Object
show all
Includes:
Releaf::Service
Defined in:
app/lib/releaf/settings/normalize_value.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.normalize_boolean(value) ⇒ Object


42
43
44
# File 'app/lib/releaf/settings/normalize_value.rb', line 42

def self.normalize_boolean(value)
  value.to_s == '1'
end

.normalize_date(value) ⇒ Object


38
39
40
# File 'app/lib/releaf/settings/normalize_value.rb', line 38

def self.normalize_date(value)
  Date.parse(value) if value.present?
end

.normalize_datetime(value) ⇒ Object


34
35
36
# File 'app/lib/releaf/settings/normalize_value.rb', line 34

def self.normalize_datetime(value)
  DateTime.parse(value) if value.present?
end

.normalize_decimal(value) ⇒ Object


18
19
20
# File 'app/lib/releaf/settings/normalize_value.rb', line 18

def self.normalize_decimal(value)
  value.to_s.sub(",", ".").to_d
end

.normalize_float(value) ⇒ Object


22
23
24
# File 'app/lib/releaf/settings/normalize_value.rb', line 22

def self.normalize_float(value)
  value.to_s.sub(",", ".").to_f
end

.normalize_integer(value) ⇒ Object


26
27
28
# File 'app/lib/releaf/settings/normalize_value.rb', line 26

def self.normalize_integer(value)
  value.to_i
end

.normalize_time(value) ⇒ Object


30
31
32
# File 'app/lib/releaf/settings/normalize_value.rb', line 30

def self.normalize_time(value)
  Time.parse(value) if value.present?
end

Instance Method Details

#callObject


6
7
8
9
10
11
12
# File 'app/lib/releaf/settings/normalize_value.rb', line 6

def call
  if self.class.respond_to? normalization_method
    self.class.send(normalization_method, value)
  else
    value
  end
end

#normalization_methodObject


14
15
16
# File 'app/lib/releaf/settings/normalize_value.rb', line 14

def normalization_method
  "normalize_#{input_type}"
end