teuton 2.3.6 → 2.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -4
  3. data/bin/teuton +1 -1
  4. data/docs/CHANGELOG.md +8 -0
  5. data/docs/changelog/v2.4.md +16 -0
  6. data/docs/dsl/definition/expect.md +11 -7
  7. data/docs/dsl/definition/result.md +7 -6
  8. data/docs/dsl/definition/run_local.md +0 -1
  9. data/docs/dsl/definition/target.md +1 -1
  10. data/docs/dsl/execution/export.md +14 -16
  11. data/docs/dsl/execution/send.md +1 -1
  12. data/docs/dsl/setting/get.md +5 -5
  13. data/docs/es/exit_code.md +59 -0
  14. data/docs/es/guess_os.md +28 -0
  15. data/docs/{Challenge-Server-Project.md → ideas/Challenge-Server-Project.md} +0 -0
  16. data/docs/{changelog → ideas}/contributions.md +0 -0
  17. data/docs/{changelog → ideas}/ideas.md +0 -0
  18. data/docs/{changelog → ideas}/servidor-de-retos.md +0 -0
  19. data/docs/learn/{example-01-target.md → 01-target.md} +1 -3
  20. data/docs/learn/{example-02-config.md → 02-config.md} +1 -3
  21. data/docs/learn/{example-03-remote-hosts.md → 03-remote_hosts.md} +10 -10
  22. data/docs/learn/{example-04-new-test.md → 04-new_test.md} +8 -16
  23. data/docs/learn/{example-05-use.md → 05-use.md} +1 -3
  24. data/docs/learn/{example-06-debug.md → 06-debug.md} +1 -3
  25. data/docs/learn/{example-07-log.md → 07-log.md} +1 -3
  26. data/docs/learn/{example-08-readme.md → 08-readme.md} +1 -3
  27. data/docs/learn/{example-09-preserve.md → 09-preserve.md} +7 -4
  28. data/docs/learn/10-result.md +36 -0
  29. data/docs/learn/11-moodle_id.md +19 -0
  30. data/docs/learn/12-get_vars.md +37 -0
  31. data/docs/learn/13-include.md +59 -0
  32. data/docs/learn/14-alias.md +47 -0
  33. data/docs/learn/16-exit_codes.md +24 -0
  34. data/docs/learn/README.md +19 -17
  35. data/lib/teuton/application.rb +24 -17
  36. data/lib/teuton/case_manager/case/builtin/main.rb +2 -3
  37. data/lib/teuton/case_manager/case/builtin/package.rb +2 -3
  38. data/lib/teuton/case_manager/case/builtin/service.rb +4 -5
  39. data/lib/teuton/case_manager/case/builtin/teuton_file.rb +3 -4
  40. data/lib/teuton/case_manager/case/builtin/teuton_host.rb +5 -6
  41. data/lib/teuton/case_manager/case/builtin/user.rb +1 -2
  42. data/lib/teuton/case_manager/case/case.rb +27 -27
  43. data/lib/teuton/case_manager/case/close.rb +2 -2
  44. data/lib/teuton/case_manager/case/config.rb +14 -14
  45. data/lib/teuton/case_manager/case/dsl/expect.rb +46 -39
  46. data/lib/teuton/case_manager/case/dsl/goto.rb +2 -2
  47. data/lib/teuton/case_manager/case/dsl/log.rb +5 -6
  48. data/lib/teuton/case_manager/case/dsl/macro.rb +11 -7
  49. data/lib/teuton/case_manager/case/dsl/main.rb +8 -8
  50. data/lib/teuton/case_manager/case/dsl/send.rb +11 -14
  51. data/lib/teuton/case_manager/case/dsl/unique.rb +1 -3
  52. data/lib/teuton/case_manager/case/main.rb +5 -5
  53. data/lib/teuton/case_manager/case/play.rb +1 -1
  54. data/lib/teuton/case_manager/case/result/ext_array.rb +9 -9
  55. data/lib/teuton/case_manager/case/result/ext_compare.rb +44 -58
  56. data/lib/teuton/case_manager/case/result/ext_filter.rb +20 -8
  57. data/lib/teuton/case_manager/case/result/result.rb +19 -18
  58. data/lib/teuton/case_manager/case/runner.rb +53 -60
  59. data/lib/teuton/case_manager/case_manager.rb +15 -15
  60. data/lib/teuton/case_manager/check_cases.rb +1 -4
  61. data/lib/teuton/case_manager/dsl.rb +5 -5
  62. data/lib/teuton/case_manager/export_manager.rb +8 -19
  63. data/lib/teuton/case_manager/hall_of_fame.rb +4 -6
  64. data/lib/teuton/case_manager/main.rb +4 -5
  65. data/lib/teuton/case_manager/report.rb +21 -16
  66. data/lib/teuton/case_manager/show.rb +2 -2
  67. data/lib/teuton/case_manager/utils.rb +13 -14
  68. data/lib/teuton/check/builtin.rb +5 -1
  69. data/lib/teuton/check/dsl.rb +10 -11
  70. data/lib/teuton/check/laboratory.rb +13 -15
  71. data/lib/teuton/check/show.rb +33 -35
  72. data/lib/teuton/cli.rb +31 -35
  73. data/lib/teuton/files/start.rb +3 -6
  74. data/lib/teuton/readme/dsl.rb +12 -6
  75. data/lib/teuton/readme/lang.rb +20 -21
  76. data/lib/teuton/readme/readme.rb +40 -42
  77. data/lib/teuton/report/close.rb +1 -3
  78. data/lib/teuton/report/formatter/array_formatter.rb +28 -39
  79. data/lib/teuton/report/formatter/base_formatter.rb +2 -13
  80. data/lib/teuton/report/formatter/csv_formatter.rb +12 -18
  81. data/lib/teuton/report/formatter/formatter_factory.rb +31 -29
  82. data/lib/teuton/report/formatter/html_formatter.rb +37 -21
  83. data/lib/teuton/report/formatter/json_formatter.rb +2 -8
  84. data/lib/teuton/report/formatter/list_formatter.rb +6 -12
  85. data/lib/teuton/report/formatter/moodle_csv_formatter.rb +3 -6
  86. data/lib/teuton/report/formatter/resume_array_formatter.rb +1 -1
  87. data/lib/teuton/report/formatter/resume_html_formatter.rb +29 -19
  88. data/lib/teuton/report/formatter/resume_json_formatter.rb +2 -3
  89. data/lib/teuton/report/formatter/resume_list_formatter.rb +4 -4
  90. data/lib/teuton/report/formatter/resume_txt_formatter.rb +14 -18
  91. data/lib/teuton/report/formatter/resume_yaml_formatter.rb +1 -9
  92. data/lib/teuton/report/formatter/txt_formatter.rb +19 -20
  93. data/lib/teuton/report/formatter/xml_formatter.rb +29 -37
  94. data/lib/teuton/report/formatter/yaml_formatter.rb +2 -12
  95. data/lib/teuton/report/report.rb +10 -10
  96. data/lib/teuton/report/show.rb +14 -33
  97. data/lib/teuton/skeleton.rb +6 -14
  98. data/lib/teuton/utils/configfile_reader.rb +22 -21
  99. data/lib/teuton/utils/name_file_finder.rb +21 -26
  100. data/lib/teuton/utils/verbose.rb +1 -2
  101. data/lib/teuton/version.rb +3 -4
  102. data/lib/teuton.rb +5 -6
  103. metadata +62 -86
  104. data/bin/check_teuton +0 -41
@@ -1,50 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rainbow'
3
+ require "colorize"
4
4
 
5
- # DSL module:
6
- # * expect_none
7
- # * expect_one
8
- # * expect_any
9
- # * expect
10
- # * expect2
11
- # * weight
12
5
  module DSL
13
- def expect_none(input)
14
- if input.class == Array
15
- input.each { |i| result.find(i) }
16
- else
17
- result.find(input)
18
- end
19
- expect2 result.count.eq(0)
20
- end
21
-
22
- def expect_one(input)
23
- if input.class == Array
24
- input.each { |i| result.find(i) }
25
- else
26
- result.find(input)
27
- end
28
- expect2 result.count.eq(1)
29
- end
30
-
31
- def expect_any(input)
32
- if input.class == Array
33
- input.each { |i| result.find(i) }
34
- else
35
- result.find(input)
36
- end
37
- expect2 result.count.gt(0)
38
- end
39
-
40
6
  # expect <condition>, :weight => <value>
41
7
  def expect(input, args = {})
42
- if input.class == TrueClass || input.class == FalseClass
8
+ if input.instance_of?(TrueClass) || input.instance_of?(FalseClass)
43
9
  expect2(input, args)
44
- elsif input.class == String || input.class == Regexp || input.class == Array
10
+ elsif input.instance_of?(String) || input.instance_of?(Regexp) || input.instance_of?(Array)
45
11
  expect_any input
46
12
  else
47
- puts "[ERROR] expect #{input} (#{input.class})"
13
+ puts "[TypeError] expect #{input} (#{input.class})"
48
14
  end
49
15
  end
50
16
 
@@ -64,7 +30,48 @@ module DSL
64
30
  app = Application.instance
65
31
  c = app.letter[:bad]
66
32
  c = app.letter[:good] if cond
67
- verbose Rainbow(c).yellow.bright
33
+ verbose c.colorize(:green)
34
+ end
35
+
36
+ def expect_any(input, args = {})
37
+ if input.instance_of? Array
38
+ input.each { |i| result.find(i) }
39
+ else
40
+ result.find(input)
41
+ end
42
+ expect2 result.count.gt(0), args
43
+ end
44
+
45
+ def expect_first(input, args = {})
46
+ @result.first
47
+ output = input
48
+ output = args[:expected] if args[:expected]
49
+ expect2 input, expected: output
50
+ end
51
+
52
+ def expect_last(input, args = {})
53
+ @result.last
54
+ output = input
55
+ output = args[:expected] if args[:expected]
56
+ expect2 input, expected: output
57
+ end
58
+
59
+ def expect_none(input, args = {})
60
+ if input.instance_of? Array
61
+ input.each { |i| result.find(i) }
62
+ else
63
+ result.find(input)
64
+ end
65
+ expect2 result.count.eq(0), args
66
+ end
67
+
68
+ def expect_one(input, args = {})
69
+ if input.instance_of? Array
70
+ input.each { |i| result.find(i) }
71
+ else
72
+ result.find(input)
73
+ end
74
+ expect2 result.count.eq(1), args
68
75
  end
69
76
 
70
77
  # Set weight value for the action
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../runner'
3
+ require_relative "../runner"
4
4
 
5
5
  # Case class -> DSL module:
6
6
  # * goto
@@ -25,7 +25,7 @@ module DSL
25
25
  @action[:command] = args[:execute].to_s if args[:execute]
26
26
  @action[:command] = args[:exec].to_s if args[:exec]
27
27
  tempfile(args[:tempfile]) if args[:tempfile]
28
- @action[:encoding] = args[:encoding] || 'UTF-8'
28
+ @action[:encoding] = args[:encoding] || "UTF-8"
29
29
 
30
30
  start_time = Time.now
31
31
  run_cmd_on(host)
@@ -7,13 +7,12 @@ module DSL
7
7
  # Record log message
8
8
  # @param text (String)
9
9
  # @param type (Symbol) Values :info, :warn or :error
10
- def log(text = '', type = :info)
11
- s = ''
12
- s = Rainbow('WARN!').color(:yellow) if type == :warn
13
- s = Rainbow('ERROR').bg(:red) if type == :error
10
+ def log(text = "", type = :info)
11
+ s = ""
12
+ s = Rainbow("WARN!").color(:yellow) if type == :warn
13
+ s = Rainbow("ERROR").bg(:red) if type == :error
14
14
  t = Time.now
15
- f = format('%<hour>02d:%<min>02d:%<sec>02d',
16
- { hour: t.hour, min: t.min, sec: t.sec })
15
+ f = format("%<hour>02d:%<min>02d:%<sec>02d", {hour: t.hour, min: t.min, sec: t.sec})
17
16
  @report.lines << "[#{f}] #{s}: #{text}"
18
17
  end
19
18
  alias msg log
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require_relative '../../../application'
3
- require 'os'
2
+
3
+ require_relative "../../../application"
4
4
 
5
5
  # DSL module methods: assert, missing_method
6
6
  module DSL
@@ -17,10 +17,10 @@ module DSL
17
17
  input.each_pair { |k, v| set(k, v) }
18
18
  errors = []
19
19
  macros[name][:args].each do |i|
20
- errors << i if get(i) == 'NODATA'
20
+ errors << i if get(i) == "NODATA"
21
21
  end
22
22
  if errors.count > 0
23
- log("Macro #{name} => required params #{errors.join(',')}",:error)
23
+ log("Macro #{name} => required params #{errors.join(",")}", :error)
24
24
  else
25
25
  instance_eval(&macros[name][:block])
26
26
  end
@@ -32,10 +32,14 @@ module DSL
32
32
  # * Invoke macro (assert)
33
33
  def method_missing(method, args = {})
34
34
  a = method.to_s
35
- if a.start_with?('_') && a.end_with?('_')
36
- return instance_eval("get(:#{a[1, a.size - 2]})")
35
+ if a.start_with?("_")
36
+ return instance_eval("get(:#{a[1, a.size - 1]})", __FILE__, __LINE__)
37
37
  end
38
- return macro a[6, a.size], args if a[0,6]=='macro_'
38
+ return macro a[6, a.size], args if a[0, 6] == "macro_"
39
39
  macro a, args
40
40
  end
41
+
42
+ def respond_to_missing?(method, *)
43
+ true
44
+ end
41
45
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'expect'
4
- require_relative 'getset'
5
- require_relative 'goto'
6
- require_relative 'log'
7
- require_relative 'macro'
8
- require_relative 'send'
9
- require_relative 'target'
10
- require_relative 'unique'
3
+ require_relative "expect"
4
+ require_relative "getset"
5
+ require_relative "goto"
6
+ require_relative "log"
7
+ require_relative "macro"
8
+ require_relative "send"
9
+ require_relative "target"
10
+ require_relative "unique"
@@ -15,22 +15,21 @@ module DSL
15
15
  host = args[:copy_to].to_s
16
16
  return unless @conn_status[host].nil?
17
17
 
18
- ip = get((host + '_ip').to_sym)
19
- username = get((host + '_username').to_sym).to_s
20
- password = get((host + '_password').to_sym).to_s
21
- port = get((host + '_port').to_sym).to_i
18
+ ip = get((host + "_ip").to_sym)
19
+ username = get((host + "_username").to_sym).to_s
20
+ password = get((host + "_password").to_sym).to_s
21
+ port = get((host + "_port").to_sym).to_i
22
22
  port = 22 if port.zero?
23
23
 
24
- filename = "#{@report.filename}.#{@report.format.to_s}"
24
+ filename = "#{@report.filename}.#{@report.format}"
25
25
  filename = "#{@report.filename}.txt" if @report.format == :colored_text
26
26
  localfilepath = File.join(@report.output_dir, filename)
27
27
  filename = args[:prefix].to_s + filename if args[:prefix]
28
28
 
29
- if args[:remote_dir]
30
- remotefilepath = File.join(args[:remote_dir], filename)
29
+ remotefilepath = if args[:remote_dir]
30
+ File.join(args[:remote_dir], filename)
31
31
  else
32
- # remotefilepath = File.join(remote_tempdir, filename)
33
- remotefilepath = File.join('.', filename)
32
+ File.join(".", filename)
34
33
  end
35
34
 
36
35
  # Upload a file or directory to the remote host
@@ -38,9 +37,9 @@ module DSL
38
37
  Net::SFTP.start(ip, username, password: password, port: port) do |sftp|
39
38
  sftp.upload!(localfilepath, remotefilepath)
40
39
  end
41
- verboseln("=> [ OK ] #{(get(:tt_members)[0,15]).ljust(16)} : #{remotefilepath}")
40
+ verboseln("=> [ OK ] #{(get(:tt_members)[0, 15]).ljust(16)} : #{remotefilepath}")
42
41
  rescue
43
- verboseln("=> [ERROR] #{(get(:tt_members)[0,15]).ljust(16)} : scp #{localfilepath} => #{remotefilepath}")
42
+ verboseln("=> [ERROR] #{(get(:tt_members)[0, 15]).ljust(16)} : scp #{localfilepath} => #{remotefilepath}")
44
43
  end
45
44
  end
46
45
 
@@ -48,7 +47,7 @@ module DSL
48
47
  return @action[:tempfile] if input.nil?
49
48
 
50
49
  name = input
51
- name = 'teuton.tmp' if input == :default
50
+ name = "teuton.tmp" if input == :default
52
51
 
53
52
  @action[:tempfile] = File.join(@tmpdir, name)
54
53
  @action[:remote_tempfile] = File.join(@remote_tmpdir, name)
@@ -57,12 +56,10 @@ module DSL
57
56
  end
58
57
 
59
58
  def tempdir
60
- # puts '[WARN] Using DSL.tempdir'
61
59
  @tmpdir
62
60
  end
63
61
 
64
62
  def remote_tempfile
65
- # puts '[WARN] Using DSL.tempfile'
66
63
  @action[:remote_tempfile]
67
64
  end
68
65
 
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Case#DSL#unique
4
3
  module DSL
5
4
  def unique(key, value)
6
5
  return if value.nil?
7
6
 
8
- k = (key.to_s + '=' + value.to_s).to_sym
9
- @uniques << k
7
+ @uniques << "#{key}=#{value}".to_sym
10
8
  end
11
9
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'dsl/main'
4
- require_relative 'config'
5
- require_relative 'close'
6
- require_relative 'play'
7
- require_relative 'runner'
3
+ require_relative "dsl/main"
4
+ require_relative "config"
5
+ require_relative "close"
6
+ require_relative "play"
7
+ require_relative "runner"
@@ -28,7 +28,7 @@ class Case
28
28
 
29
29
  def close_opened_sessions
30
30
  @sessions.each_value do |s|
31
- s.close if s.class == Net::SSH::Connection::Session
31
+ s.close if s.instance_of? Net::SSH::Connection::Session
32
32
  end
33
33
  end
34
34
 
@@ -3,12 +3,12 @@
3
3
  # This is an extension of Result class
4
4
  class Result
5
5
  def count
6
- @alterations << 'count'
7
- if @content.class == Array
6
+ @alterations << "count"
7
+ if @content.instance_of? Array
8
8
  @content = [@content.count]
9
9
  self
10
10
  elsif @content.nil?
11
- @content = ['0']
11
+ @content = ["0"]
12
12
  else
13
13
  @content = [@content.to_i.to_s]
14
14
  end
@@ -31,13 +31,13 @@ class Result
31
31
  end
32
32
 
33
33
  def empty
34
- @expected = 'Empty!'
34
+ @expected = "Empty!"
35
35
  @content.empty
36
36
  end
37
37
 
38
- alias count! count
39
- alias length count
40
- alias len count
41
- alias size count
42
- alias empty? empty
38
+ alias count! count
39
+ alias length count
40
+ alias len count
41
+ alias size count
42
+ alias empty? empty
43
43
  end
@@ -1,104 +1,93 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # This is an extension of Result class
4
- # rubocop:disable Metrics/ClassLength
5
4
  class Result
6
- # rubocop:disable Metrics/MethodLength
7
- # Return true when content is equal than input
8
- # @param input (Object)
9
5
  def eq(input)
6
+ # Return true when content is equal than input
10
7
  @expected = input
11
8
 
12
9
  case input.class.to_s
13
- when 'Fixnum'
10
+ when "Fixnum"
14
11
  value = @content[0].to_i
15
- puts '[WARN] Fixnum class is deprecated!'
16
- puts ' Upgrade your Ruby version.'
17
- when 'Float'
12
+ puts "[WARN] Fixnum is a Ruby deprecated class!"
13
+ puts " (Upgrade your Ruby version)"
14
+ when "Float"
18
15
  value = @content[0].to_f
19
- when 'Integer'
16
+ when "Integer"
20
17
  value = @content[0].to_i
21
- when 'String'
18
+ when "String"
22
19
  value = @content[0].to_s
23
20
  else
24
21
  value = @content[0]
25
22
  end
26
23
  value == input
27
24
  end
28
- # rubocop:enable Metrics/MethodLength
29
- alias eq? eq
30
- alias equal eq
31
- alias equal? eq
32
- alias is_equal? eq
25
+ alias eq? eq
26
+ alias equal eq
27
+ alias equal? eq
28
+ alias is_equal? eq
33
29
 
34
- # rubocop:disable Metrics/MethodLength
35
30
  def neq(external)
36
31
  @expected = "Not equal to #{external}"
37
32
 
38
33
  case external.class.to_s
39
- when 'Fixnum'
34
+ when "Fixnum"
40
35
  internal = @content[0].to_i
41
- puts '[WARN] Fixnum class is deprecated!'
42
- puts ' Upgrade your Ruby version.'
43
- when 'Float'
36
+ puts "[WARN] Fixnum class is deprecated!"
37
+ puts " Upgrade your Ruby version."
38
+ when "Float"
44
39
  internal = @content[0].to_f
45
- when 'Integer'
40
+ when "Integer"
46
41
  internal = @content[0].to_i
47
42
  else
48
43
  internal = @content[0]
49
44
  end
50
45
  internal != external
51
46
  end
52
- # rubocop:enable Metrics/MethodLength
53
- alias neq? neq
54
- alias not_equal neq
47
+ alias neq? neq
48
+ alias not_equal neq
55
49
  alias not_equal? neq
56
50
 
57
- # rubocop:disable Metrics/MethodLength
58
51
  def ge(input)
59
52
  @expected = "Greater or equal to #{input}"
60
53
  return false if @content.nil? || @content[0].nil?
61
54
 
62
55
  value = @content[0]
63
56
  case input.class.to_s
64
- when 'Fixnum'
57
+ when "Fixnum"
65
58
  value = @content[0].to_i
66
- puts '[WARN] Fixnum class is deprecated!'
67
- puts ' Upgrade your Ruby version.'
68
- when 'Float'
59
+ puts "[WARN] Fixnum class is deprecated!"
60
+ puts " Upgrade your Ruby version."
61
+ when "Float"
69
62
  value = @content[0].to_f
70
- when 'Integer'
63
+ when "Integer"
71
64
  value = @content[0].to_i
72
65
  end
73
66
  value >= input
74
67
  end
75
- # rubocop:enable Metrics/MethodLength
76
- alias greater_or_equal ge
68
+ alias greater_or_equal ge
77
69
  alias greater_or_equal? ge
78
70
 
79
- # rubocop:disable Metrics/MethodLength
80
71
  def gt(input)
81
72
  @expected = "Greater than #{input}"
82
73
  return false if @content.nil? || @content[0].nil?
83
74
 
84
75
  value = @content[0]
85
76
  case input.class.to_s
86
- when 'Fixnum'
77
+ when "Fixnum"
87
78
  value = @content[0].to_i
88
- puts '[WARN] Fixnum class is deprecated!'
89
- puts ' Upgrade your Ruby version.'
90
- when 'Float'
79
+ puts "[WARN] Fixnum class is deprecated!"
80
+ puts " Upgrade your Ruby version."
81
+ when "Float"
91
82
  value = @content[0].to_f
92
- when 'Integer'
83
+ when "Integer"
93
84
  value = @content[0].to_i
94
85
  end
95
86
  value > input
96
87
  end
97
- # rubocop:enable Metrics/MethodLength
98
- alias greater gt
99
- alias greater_than gt
88
+ alias greater gt
89
+ alias greater_than gt
100
90
 
101
- # rubocop:disable Metrics/MethodLength
102
91
  def le(input)
103
92
  @expected = "Lesser or equal to #{input}"
104
93
 
@@ -106,41 +95,38 @@ class Result
106
95
 
107
96
  value = @content[0]
108
97
  case input.class.to_s
109
- when 'Fixnum'
98
+ when "Fixnum"
110
99
  value = @content[0].to_i
111
- puts '[WARN] Fixnum class is deprecated!'
112
- puts ' Upgrade your Ruby version.'
113
- when 'Float'
100
+ puts "[WARN] Fixnum class is deprecated!"
101
+ puts " Upgrade your Ruby version."
102
+ when "Float"
114
103
  value = @content[0].to_f
115
- when 'Integer'
104
+ when "Integer"
116
105
  value = @content[0].to_i
117
106
  end
118
107
  value <= input
119
108
  end
120
- # rubocop:enable Metrics/MethodLength
121
- alias lesser_or_equal le
109
+ alias lesser_or_equal le
122
110
  alias lesser_or_equal? le
123
111
 
124
- # rubocop:disable Metrics/MethodLength
125
112
  def lt(input)
126
113
  @expected = "Lesser than #{input}"
127
114
  return false if @content.nil? || @content[0].nil?
128
115
 
129
116
  value = @content[0]
130
117
  case input.class.to_s
131
- when 'Fixnum'
118
+ when "Fixnum"
132
119
  value = @content[0].to_i
133
- puts '[WARN] Fixnum class is deprecated!'
134
- puts ' Upgrade your Ruby version.'
135
- when 'Float'
120
+ puts "[WARN] Fixnum class is deprecated!"
121
+ puts " Upgrade your Ruby version."
122
+ when "Float"
136
123
  value = @content[0].to_f
137
- when 'Integer'
124
+ when "Integer"
138
125
  value = @content[0].to_i
139
126
  end
140
127
  value < input
141
128
  end
142
- # rubocop:enable Metrics/MethodLength
143
- alias lesser lt
129
+ alias lesser lt
144
130
  alias smaller lt
145
131
  alias lesser_than lt
146
132
 
@@ -151,7 +137,7 @@ class Result
151
137
  return false if @content.nil?
152
138
 
153
139
  target = @content[0].to_f
154
- desv = (target * 10.0) / 100.0
140
+ desv = (target * 10.0) / 100.0
155
141
  return true if (target - input.to_f).abs.to_f <= desv
156
142
 
157
143
  false
@@ -6,18 +6,24 @@ class Result
6
6
  def find(filter)
7
7
  @alterations << "find(#{filter})"
8
8
  case filter.class.to_s
9
- when 'Array'
9
+ when "Array"
10
10
  find_when_array(filter)
11
- when 'String' || 'Integer'
11
+ when "String" || "Integer"
12
12
  @content.select! { |i| i.include?(filter.to_s) }
13
- when 'Regexp'
13
+ when "Regexp"
14
14
  @content.select! { |i| filter.match(i) }
15
15
  end
16
16
  self
17
17
  end
18
- alias grep find
19
- alias grep! find
20
- alias find! find
18
+ alias grep find
19
+ alias grep! find
20
+ alias find! find
21
+
22
+ def first
23
+ @alterations << "first"
24
+ @content = [@content.first]
25
+ self
26
+ end
21
27
 
22
28
  def not_find(p_filter)
23
29
  @alterations << "not_find(#{p_filter})"
@@ -32,7 +38,7 @@ class Result
32
38
  @alterations << "since(#{filter})"
33
39
  return self if @content.size.zero?
34
40
 
35
- if filter.class == String
41
+ if filter.instance_of? String
36
42
  flag = false
37
43
  @content.select! do |i|
38
44
  flag = true if i.include?(filter.to_s)
@@ -42,11 +48,17 @@ class Result
42
48
  self
43
49
  end
44
50
 
51
+ def last
52
+ @alterations << "last"
53
+ @content = [@content.last]
54
+ self
55
+ end
56
+
45
57
  def until(filter)
46
58
  @alterations << "until(#{filter})"
47
59
  return self if @content.size.zero?
48
60
 
49
- if filter.class == String
61
+ if filter.instance_of? String
50
62
  flag = true
51
63
  @content.select! do |i|
52
64
  flag = false if i.include?(filter.to_s)
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'ext_array'
4
- require_relative 'ext_compare'
5
- require_relative 'ext_filter'
3
+ require_relative "ext_array"
4
+ require_relative "ext_compare"
5
+ require_relative "ext_filter"
6
6
 
7
7
  # This object contains data returned by remote/local execution
8
8
  # * initialize
@@ -22,7 +22,7 @@ class Result
22
22
  end
23
23
 
24
24
  def alterations
25
- @alterations.join(' & ')
25
+ @alterations.join(" & ")
26
26
  end
27
27
 
28
28
  def content=(content)
@@ -30,30 +30,31 @@ class Result
30
30
  @content = content.clone
31
31
  end
32
32
 
33
- def reset
34
- @content_backup = []
35
- @content = []
36
- @exitstatus = nil
37
- @value = nil
38
- @expected = nil
39
- @alterations = []
40
- end
41
-
42
33
  def debug
43
- print "\n" + '*' * 20
34
+ print "\n" + "*" * 20
44
35
  print " [DEBUG] count=#{@content.count} "
45
- puts '*' * 20
36
+ puts "*" * 20
46
37
  @content.each_with_index do |item, index|
47
- puts format('%<index>2d: %<item>s', { index: index, item: item })
38
+ puts format("%<index>2d: %<item>s", {index: index, item: item})
48
39
  end
49
- puts '*' * 57
40
+ puts "*" * 57
50
41
  end
51
42
 
52
43
  def expected
53
44
  @expected.to_s
54
45
  end
55
46
 
47
+ def reset
48
+ @content_backup = []
49
+ @content = []
50
+ @exitstatus = nil
51
+ @value = nil
52
+ @expected = nil
53
+ @alterations = []
54
+ end
55
+
56
56
  def ok?
57
+ # REVISE THIS
57
58
  return false if @exitstatus.nil?
58
59
 
59
60
  @exitstatus.zero?
@@ -63,7 +64,7 @@ class Result
63
64
  temp = @content_backup.clone
64
65
  reset
65
66
  @content_backup = temp
66
- @content = temp.clone
67
+ @content = temp.clone
67
68
  end
68
69
  alias restore! restore
69
70