lib/ayadn/set.rb in ayadn-1.0.3 vs lib/ayadn/set.rb in ayadn-1.0.4
- old
+ new
@@ -132,12 +132,11 @@
end
def save
Settings.save_config
end
def validate(t)
- t = t.to_i
- t >= 0.7 ? t : 1.5
+ Validators.timer(t)
end
def timer(t)
Settings.options[:scroll][:timer] = t
end
end
@@ -156,16 +155,11 @@
end
def save
Settings.save_config
end
def validate(value)
- case value
- when "TRUE", "true", "1", "yes"
- true
- when "FALSE", "false", "0", "no"
- false
- end
+ Validators.boolean(value)
end
def auto_save_sent_posts(value)
Settings.options[:backup][:auto_save_sent_posts] = value
end
def auto_save_sent_messages(value)
@@ -174,10 +168,42 @@
def auto_save_lists(value)
Settings.options[:backup][:auto_save_lists] = value
end
end
+ class Validators
+ def self.boolean(value)
+ case value.downcase
+ when "true", "1", "yes"
+ true
+ when "false", "0", "no"
+ false
+ else
+ abort(Status.error_missing_parameters)
+ end
+ end
+ def self.index_range(min, max, value)
+ x = value.to_i
+ if x >= min && x <= max
+ x
+ else
+ abort(Status.must_be_integer)
+ end
+ end
+ def self.timer(t)
+ t = t.to_i
+ t >= 1 ? t : 3
+ end
+ def self.color(color)
+ colors_list = %w{red green magenta cyan yellow blue white}
+ unless colors_list.include?(color)
+ puts Status.error_missing_parameters
+ abort(Status.valid_colors(colors_list))
+ end
+ end
+ end
+
class SetCounts
def initialize
Settings.load_config
Settings.get_token
Settings.init_config
@@ -190,20 +216,11 @@
end
def save
Settings.save_config
end
def validate(value)
- if value.is_integer?
- x = value
- else
- x = value.to_i
- end
- if x >= 1 && x <= 200
- x
- else
- abort(Status.must_be_integer)
- end
+ Validators.index_range(1, 200, value)
end
def default(value)
Settings.options[:counts][:default] = value
end
def unified(value)
@@ -259,16 +276,11 @@
Settings.get_token
Settings.init_config
Logs.create_logger
end
def validate(value)
- case value
- when "TRUE", "true", "1", "yes"
- 1
- when "FALSE", "false", "0", "no"
- 0
- end
+ Validators.boolean(value)
end
def log(args)
x = "New value for '#{args[0]}' in 'Timeline' => #{args[1]}"
puts "\n#{x}\n".color(:cyan)
Logs.rec.info x
@@ -311,14 +323,10 @@
Settings.init_config
Logs.create_logger
end
def validate(color)
- colors_list = %w{red green magenta cyan yellow blue white}
- unless colors_list.include?(color)
- puts Status.error_missing_parameters
- abort(Status.valid_colors(colors_list))
- end
+ Validators.color(color)
end
def log(args)
x = "New value for '#{args[0]}' in 'Colors' => #{args[1]}"
puts "\n#{x}\n".color(:cyan)