Class: Xipai::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/xipai/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, _options)
  @timestamp = Time.now
  @mode      = _mode
  @hashcode  = _hashcode
  @result    = _set
  @options   = _options
end

Instance Attribute Details

#hashcodeObject

Returns the value of attribute hashcode.



10
11
12
# File 'lib/xipai/result.rb', line 10

def hashcode
  @hashcode
end

#modeObject

Returns the value of attribute mode.



10
11
12
# File 'lib/xipai/result.rb', line 10

def mode
  @mode
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/xipai/result.rb', line 10

def options
  @options
end

#resultObject

Returns the value of attribute result.



10
11
12
# File 'lib/xipai/result.rb', line 10

def result
  @result
end

#timestampObject

Returns the value of attribute timestamp.



10
11
12
# File 'lib/xipai/result.rb', line 10

def timestamp
  @timestamp
end

Instance Method Details

#data_jsonObject



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[options].match do |m|
    m.some(->(x){["true" , true,  1, "verbose"].include?(x[:verbose])}) {
      {
        timestamp: timestamp,
        mode:      mode,
        hashcode:  hashcode,
        result:    result,
        options:   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[options].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_dataObject



56
57
58
59
60
61
# File 'lib/xipai/result.rb', line 56

def replay_data
  return hash_deep_stringize(options.dup.tap {|me|
    me.delete(:replay_output)
    me[:mode] = me[:mode].to_s
  })
end

#replay_output?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/xipai/result.rb', line 71

def replay_output?
  return ![nil, ""].include?(options[:replay_output])
end

#replay_output_pathObject



63
64
65
66
67
68
69
# File 'lib/xipai/result.rb', line 63

def replay_output_path
  return nil if [nil, ""].include?(options[:replay_output])
  basename = File.basename(options[:replay_output]).tap {|me|
    break me += ".xipai-replay.yaml" if me !~ /\A(?:.*\.(?:yaml|yml))\z/xo
  }
  return "#{File.dirname(options[:replay_output])}/#{basename}"
end