class Fcoin::MarketValidator
Attributes
level[RW]
method_name[RW]
resolution[RW]
Public Class Methods
new(params)
click to toggle source
@params params [Hash] Parameter you want to verify including the called method name @option params :level [String or Symbol] Level of depth chart @option params :resolution [String or Symbol] period of Candles Chart @option params :method_name [String or Symbol] invoked method name
# File lib/fcoin/validator/market_validator.rb, line 11 def initialize(params) self.level = params[:level] self.resolution = params[:resolution] self.method_name = params[:method_name] end
Public Instance Methods
messages()
click to toggle source
Error message when invalid
# File lib/fcoin/validator/market_validator.rb, line 28 def messages return {} if valid? results = [] case method_name when /market_depth|on_depth/ results << includes_error_message(level, :level, valid_levels) unless valid_level? when /market_candles|on_candle/ results << includes_error_message(resolution, :resolution, valid_resolutions) unless valid_resolution? end results.compact&.each_with_object({}) { |message, data| data.merge!(message) } end
valid?()
click to toggle source
Validate according to method_name
# File lib/fcoin/validator/market_validator.rb, line 18 def valid? case method_name when /market_depth|on_depth/ valid_level? when /market_candles|on_candle/ valid_resolution? end end
Private Instance Methods
valid_level?()
click to toggle source
# File lib/fcoin/validator/market_validator.rb, line 44 def valid_level? level.to_s.in? valid_levels end
valid_levels()
click to toggle source
# File lib/fcoin/validator/market_validator.rb, line 52 def valid_levels ::Settings.fcoin.validation.params.level end
valid_resolution?()
click to toggle source
# File lib/fcoin/validator/market_validator.rb, line 48 def valid_resolution? resolution.to_s.in? valid_resolutions end
valid_resolutions()
click to toggle source
# File lib/fcoin/validator/market_validator.rb, line 56 def valid_resolutions ::Settings.fcoin.validation.params.resolution end