ruval 0.1.0 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b863b7435fb17b88d4ffd5daa5d1ca2a0222e2a57d3cd429fbea1f57d06c433
4
- data.tar.gz: 4a2771ba61e7ff6a3baa0e809907b34c7f6bba63f1c0720c94d932b0ae9f2291
3
+ metadata.gz: 43ddb4cd97827b47d98782f74a8787e4ade6359dd7c517ff4c783932e966741b
4
+ data.tar.gz: 2008faeca570a7cebd3e911c0c2526e76c6218a7f1a8c12bfdf9f08b3e886561
5
5
  SHA512:
6
- metadata.gz: 219ac8814e1c26af0f1082e6249f40817c0ac5ac3590daf6ff18a04937d83ddb4aa5c8a4bddbc955359a1f3b66575dfb3d6795895fdad76dd8ef6cd11329bbf7
7
- data.tar.gz: a339bf6e4baaf077c8c06339bb084b4effb7acfea61e3f7ba6e2ea23de10b6e552491609c826a898a4ce086c9944b3848e7d150875ddef41da0e33ed7ab0d820
6
+ metadata.gz: dc8f0326c17468d41f7a49f17466b21dfdfd37e6e9b21849cf997f3a888707210e9694cbd4494e6e52c8c27307a1069ecf126bfc4ba72551487e19abacdd3219
7
+ data.tar.gz: a302f41c9be53069e9f9bd3603f219c86b049035357eeaad03fced72268c4e177192de8ec015973b2dce7d14487ed46e38ff33e264510f05dc501ab2f9c9df7d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruval (0.1.0)
4
+ ruval (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ # TODO
2
+
3
+ [ ] ignore keywords inside strings. Eg the parenthesis in this line causes problems:
4
+ def good; ':)'; end
5
+ [x] add option '-c' to colorize (with green) the returned values
6
+
1
7
  # Ruval
2
8
 
3
9
  Consider this program:
data/exe/rv CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
4
 
5
- system("ruval #{ARGV.join(' ')}")
5
+ require "ruval"
@@ -11,7 +11,7 @@ end
11
11
  # vim: ft=ruby:syntax=ruby
12
12
 
13
13
  DEFAULT_NEWLINES = 1
14
- KEYWORDS_REGEX = /\b(?:class|module|def|if|do|end)\b/
14
+ KEYWORDS_REGEX = /\b(?:class|module|def|if|do|end)\b|[{}\[\]()]/
15
15
 
16
16
  def prog
17
17
  File.basename $0
@@ -47,17 +47,20 @@ end
47
47
 
48
48
  file = ARGV.shift
49
49
 
50
+ opts = {}
50
51
  if ARGV.include?('-n')
51
- _, line_spacing = ARGV[ARGV.index('-n'),2]
52
- line_spacing = line_spacing.to_i
52
+ _, opts[:line_spacing]= ARGV[ARGV.index('-n'),2]
53
+ opts[:line_spacing] = opts[:line_spacing].to_i
53
54
  end
54
- line_spacing ||= DEFAULT_NEWLINES
55
+ opts[:line_spacing] ||= DEFAULT_NEWLINES
55
56
 
56
- if line_spacing < 0
57
+ if opts[:line_spacing] < 0
57
58
  puts "line_spacing cannot be negative"
58
59
  exit
59
60
  end
60
61
 
62
+ opts[:colorize] = ARGV.include?('-c') ? true : false
63
+
61
64
  # get longest line
62
65
  longest = 0
63
66
  File.read(file).each_line do |l|
@@ -71,7 +74,7 @@ def update_scope(line, line_stack, scope)
71
74
  return if keywords.empty? && scope.empty?
72
75
  line_stack << line
73
76
  keywords.each do |kw|
74
- unless kw == 'end'
77
+ unless %w"end } ] )".include?(kw)
75
78
  scope.push kw
76
79
  else
77
80
  scope.pop
@@ -86,11 +89,19 @@ File.read(file).each_line do |l|
86
89
  update_scope(l, line_stack, scope)
87
90
  next if(comment?(l) || l.strip.empty? || !scope.empty?)
88
91
  l = if line_stack.empty?
89
- line_spacing == 0 ? l.remove_comments(longest) : l
92
+ opts[:line_spacing] == 0 ? l.remove_comments(longest) : l
90
93
  else
91
- line_stack.join
94
+ line_stack.slice!(0,line_stack.length).join
92
95
  end
93
- line_stack = []
94
- puts l + "=> #{eval l, TOPLEVEL_BINDING}" + "\n"*line_spacing
96
+ value = eval(l, TOPLEVEL_BINDING)
97
+ value = if value.class == String
98
+ "\"#{value}\""
99
+ elsif value.class == Symbol
100
+ ":#{value}"
101
+ else
102
+ value
103
+ end
104
+ color = opts[:colorize] ? "\e[32m" : "\e[m"
105
+ puts l + "#{color}=> #{value}\e[m" + "\n" * opts[:line_spacing]
95
106
  end
96
107
 
@@ -1,3 +1,3 @@
1
1
  module Ruval
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergio
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-17 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Print the value of every statement in a Ruby progam
14
14
  email:
@@ -33,11 +33,11 @@ files:
33
33
  - lib/ruval.rb
34
34
  - lib/ruval/version.rb
35
35
  - ruval.gemspec
36
- homepage:
36
+ homepage:
37
37
  licenses:
38
38
  - MIT
39
39
  metadata: {}
40
- post_install_message:
40
+ post_install_message:
41
41
  rdoc_options: []
42
42
  require_paths:
43
43
  - lib
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubygems_version: 3.1.4
56
- signing_key:
56
+ signing_key:
57
57
  specification_version: 4
58
58
  summary: Print the value of every statement in a Ruby progam
59
59
  test_files: []