Class: Fcoin::MarketValidator
- Inherits:
-
Object
- Object
- Fcoin::MarketValidator
- Includes:
- ValidatorUtility
- Defined in:
- lib/fcoin/validator/market_validator.rb
Instance Method Summary collapse
-
#initialize(params) ⇒ MarketValidator
constructor
A new instance of MarketValidator.
-
#messages ⇒ Object
Error message when invalid.
-
#valid? ⇒ Boolean
Validate according to method_name.
Methods included from ValidatorUtility
#between_error_message, #includes_error_message, #presence_error_message
Constructor Details
#initialize(params) ⇒ MarketValidator
Returns a new instance of MarketValidator.
11 12 13 14 15 |
# 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 |
Instance Method Details
#messages ⇒ Object
Error message when invalid
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fcoin/validator/market_validator.rb', line 28 def return {} if valid? results = [] case method_name when /market_depth|on_depth/ results << (level, :level, valid_levels) unless valid_level? when /market_candles|on_candle/ results << (resolution, :resolution, valid_resolutions) unless valid_resolution? end results.compact&.each_with_object({}) { |, data| data.merge!() } end |
#valid? ⇒ Boolean
Validate according to method_name
18 19 20 21 22 23 24 25 |
# 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 |