lib/ayadn/set.rb in ayadn-1.6.0 vs lib/ayadn/set.rb in ayadn-1.7.0

- old
+ new

@@ -60,11 +60,11 @@ timeline_config = SetTimeline.new if args[0] begin param = timeline_config.validate(args[1]) timeline_config.send(args[0], param) - rescue NoMethodError + rescue NoMethodError, ArgumentError puts Status.error_missing_parameters exit rescue => e raise e end @@ -82,11 +82,11 @@ counts_config = SetCounts.new if args[0] begin param = counts_config.validate(args[1]) counts_config.send(args[0], param) - rescue NoMethodError + rescue NoMethodError, ArgumentError puts Status.error_missing_parameters exit rescue => e raise e end @@ -106,11 +106,11 @@ color_config = SetColor.new if args[0] begin color_config.validate(args[1]) color_config.send(args[0], args[1]) - rescue NoMethodError + rescue NoMethodError, ArgumentError puts Status.error_missing_parameters exit rescue => e raise e end @@ -127,11 +127,11 @@ backup_config = SetBackup.new if args[0] begin param = backup_config.validate(args[1]) backup_config.send(args[0], param) - rescue NoMethodError + rescue NoMethodError, ArgumentError puts Status.error_missing_parameters exit rescue => e raise e end @@ -146,11 +146,57 @@ long_desc Descriptions.set_defaults def defaults Settings.restore_defaults puts Status.done 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.cache_range value + if value >= 1 && value <= 168 + value.round + else + abort(Status.cache_range) + end + end + def self.threshold value + value = value.to_f + if value > 0 and value < 5 + value + else + abort(Status.threshold) + 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 black} + unless colors_list.include?(color) + puts Status.error_missing_parameters + abort(Status.valid_colors(colors_list)) + end + end end class SetScroll def initialize Settings.load_config @@ -220,11 +266,11 @@ Settings.get_token Settings.init_config Logs.create_logger end def log(args) - x = "New value for '#{args[0]}' in 'NiceRank' => #{"%1.1f" % args[1].to_f}" + x = "New value for '#{args[0]}' in 'NiceRank' => #{args[1]}" puts "\n#{x}\n".color(:cyan) Logs.rec.info x end def save Settings.save_config @@ -259,66 +305,18 @@ Settings.save_config end def validate(value) 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) - Settings.options[:backup][:auto_save_sent_messages] = value - end - 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 + def method_missing(meth, options) + case meth.to_s + when 'auto_save_sent_posts', 'auto_save_sent_messages', 'auto_save_lists' + Settings.options[:backup][meth.to_sym] = options else - abort(Status.error_missing_parameters) + super 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.cache_range value - if value >= 1 && value <= 168 - value.round - else - abort(Status.cache_range) - end - end - def self.threshold value - value = value.to_f - if value > 0 and value < 5 - value - else - abort(Status.threshold) - 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 black} - 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 @@ -335,58 +333,18 @@ Settings.save_config end def validate(value) Validators.index_range(1, 200, value) end - def default(value) - Settings.options[:counts][:default] = value + def method_missing(meth, options) + case meth.to_s + when 'default', 'unified', 'checkins', 'conversations', 'global', 'photos', 'trending', 'mentions', 'convo', 'posts', 'messages', 'search', 'whoreposted', 'whostarred', 'whatstarred', 'files' + Settings.options[:counts][meth.to_sym] = options.to_i + else + super + end end - def unified(value) - Settings.options[:counts][:unified] = value - end - def global(value) - Settings.options[:counts][:global] = value - end - def checkins(value) - Settings.options[:counts][:checkins] = value - end - def conversations(value) - Settings.options[:counts][:conversations] = value - end - def photos(value) - Settings.options[:counts][:photos] = value - end - def trending(value) - Settings.options[:counts][:trending] = value - end - def mentions(value) - Settings.options[:counts][:mentions] = value - end - def convo(value) - Settings.options[:counts][:convo] = value - end - def posts(value) - Settings.options[:counts][:posts] = value - end - def messages(value) - Settings.options[:counts][:messages] = value - end - def search(value) - Settings.options[:counts][:search] = value - end - def whoreposted(value) - Settings.options[:counts][:whoreposted] = value - end - def whostarred(value) - Settings.options[:counts][:whostarred] = value - end - def whatstarred(value) - Settings.options[:counts][:whatstarred] = value - end - def files(value) - Settings.options[:counts][:files] = value - end end class SetTimeline def initialize Settings.load_config @@ -403,42 +361,20 @@ Logs.rec.info x end def save Settings.save_config end - def directed(value) - Settings.options[:timeline][:directed] = value + def method_missing(meth, options) + case meth.to_s + when 'directed', 'html', 'show_source', 'show_symbols', 'show_real_name', 'show_date', 'show_spinner', 'show_debug' + Settings.options[:timeline][meth.to_sym] = options + when 'deleted', 'annotations' + abort(Status.not_mutable) + else + super + end end - def deleted(value) - #Settings.options[:timeline][:deleted] = value - abort(Status.not_mutable) - end - def html(value) - Settings.options[:timeline][:html] = value - end - def annotations(value) - #Settings.options[:timeline][:annotations] = value - abort(Status.not_mutable) - end - def show_source(value) - Settings.options[:timeline][:show_source] = value - end - def show_symbols(value) - Settings.options[:timeline][:show_symbols] = value - end - def show_real_name(value) - Settings.options[:timeline][:show_real_name] = value - end - def show_date(value) - Settings.options[:timeline][:show_date] = value - end - def show_spinner value - Settings.options[:timeline][:show_spinner] = value - end - def show_debug value - Settings.options[:timeline][:show_debug] = value - end end class SetColor def initialize Settings.load_config @@ -459,70 +395,19 @@ def save Settings.save_config end - def id(color) - Settings.options[:colors][:id] = color.to_sym - end - - def index(color) - Settings.options[:colors][:index] = color.to_sym - end - - def username(color) - Settings.options[:colors][:username] = color.to_sym - end - - def name(color) - Settings.options[:colors][:name] = color.to_sym - end - - def date(color) - Settings.options[:colors][:date] = color.to_sym - end - - def link(color) - Settings.options[:colors][:link] = color.to_sym - end - - def dots(color) - Settings.options[:colors][:dots] = color.to_sym - end - - def hashtags(color) - Settings.options[:colors][:hashtags] = color.to_sym - end - - def hashtag color - hashtags color - end - - def mentions(color) - Settings.options[:colors][:mentions] = color.to_sym - end - - def mention color - mentions color - end - - def source(color) - Settings.options[:colors][:source] = color.to_sym - end - - def client color - source color - end - - def symbols(color) - Settings.options[:colors][:symbols] = color.to_sym - end - - def symbol(color) - symbols color - end - - def debug(color) - Settings.options[:colors][:debug] = color.to_sym + def method_missing(meth, options) + case meth.to_s + when 'id', 'index', 'username', 'name', 'date', 'link', 'dots', 'hashtags', 'mentions', 'source', 'symbols', 'debug' + Settings.options[:colors][meth.to_sym] = options.to_sym + when 'hashtag', 'mention', 'symbol' + Settings.options[:colors]["#{meth}s".to_sym] = options.to_sym + when 'client' + Settings.options[:colors][:source] = options.to_sym + else + super + end end end end