Class: Xipai::Result
- Inherits:
-
Object
- Object
- Xipai::Result
- Defined in:
- lib/xipai/result.rb
Instance Attribute Summary collapse
-
#hashcode ⇒ Object
Returns the value of attribute hashcode.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#options ⇒ Object
Returns the value of attribute options.
-
#result ⇒ Object
Returns the value of attribute result.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #data_json ⇒ Object
-
#initialize(_mode, _hashcode, _set, _options) ⇒ Result
constructor
A new instance of Result.
- #replay_data ⇒ Object
- #replay_output? ⇒ Boolean
- #replay_output_path ⇒ Object
Constructor Details
#initialize(_mode, _hashcode, _set, _options) ⇒ Result
Returns a new instance of Result.
12 13 14 15 16 17 18 |
# File 'lib/xipai/result.rb', line 12 def initialize(_mode, _hashcode, _set, ) @timestamp = Time.now @mode = _mode @hashcode = _hashcode @result = _set @options = end |
Instance Attribute Details
#hashcode ⇒ Object
Returns the value of attribute hashcode.
10 11 12 |
# File 'lib/xipai/result.rb', line 10 def hashcode @hashcode end |
#mode ⇒ Object
Returns the value of attribute mode.
10 11 12 |
# File 'lib/xipai/result.rb', line 10 def mode @mode end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/xipai/result.rb', line 10 def @options end |
#result ⇒ Object
Returns the value of attribute result.
10 11 12 |
# File 'lib/xipai/result.rb', line 10 def result @result end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
10 11 12 |
# File 'lib/xipai/result.rb', line 10 def @timestamp end |
Instance Method Details
#data_json ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/xipai/result.rb', line 20 def data_json data = Some[].match do |m| m.some(->(x){["true" , true, 1, "verbose"].include?(x[:verbose])}) { { timestamp: , mode: mode, hashcode: hashcode, result: result, options: } } m.some(->(x){["false", false, 0, nil, ""].include?(x[:verbose]) }) { { mode: mode, hashcode: hashcode, result: result, } } m.some {raise "Error: verbose mode option value is invalid."} end data = Some[].match do |m| m.some(->(x){["true", true, 1, "without_hashcode"].include?(x[:without_hashcode]) }) { data.delete(:hashcode) data } m.some(->(x){["false", false, 0, "", nil].include?(x[:without_hashcode]) }) { data } m.some {raise "Error: without_hashcode option value is invalid."} end return data_json_string(data) end |
#replay_data ⇒ Object
56 57 58 59 60 61 |
# File 'lib/xipai/result.rb', line 56 def replay_data return hash_deep_stringize(.dup.tap {|me| me.delete(:replay_output) me[:mode] = me[:mode].to_s }) end |
#replay_output? ⇒ Boolean
71 72 73 |
# File 'lib/xipai/result.rb', line 71 def replay_output? return ![nil, ""].include?([:replay_output]) end |
#replay_output_path ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/xipai/result.rb', line 63 def replay_output_path return nil if [nil, ""].include?([:replay_output]) basename = File.basename([:replay_output]).tap {|me| break me += ".xipai-replay.yaml" if me !~ /\A(?:.*\.(?:yaml|yml))\z/xo } return "#{File.dirname([:replay_output])}/#{basename}" end |