ruval 0.1.1 → 0.1.6

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: a9e95238de384e07298f90c3d89a397453b18ffbfc19091d3e7b1a4d3b597e48
4
- data.tar.gz: a82a876b3674785d38bac2e56ab500dbdd4dbf7e47d4dad7e8fc1f25aae2eb68
3
+ metadata.gz: 51d35aa42146e2d865251e44a2469aba31eefcd058b3c4e74014fa770a436258
4
+ data.tar.gz: 94c389acd01473b8197ae1ce71f9903d4e38b11e0473130aba0e0454c5668dfa
5
5
  SHA512:
6
- metadata.gz: 664630ff5bebf546d7c0526f67daa896f4173459bf0ea1a8dad7154228076b156509b502c2f6cd6da1955f15f17ce91d76506c5b1b77d09ea92bc26b0c5e661a
7
- data.tar.gz: fa44e6ebcca1fc2331053ef8b714c0605abfd3c3c97e6148331bc41381cb3c1284be9f781081090488d66d12d5ce0d2cd768632d874cfb310618972877070a20
6
+ metadata.gz: e9f0df1791fecc145fa4471676035d71ad1ed02bf343bfe370024431d722f0530f1db33a56eb4d37e7a21137f171214fead831009a3b8b2f953293b62cd5ae90
7
+ data.tar.gz: 265bb7d0bd26d8debc11839946dada99c2064129238bf782db79e136867a0c099ddffba02cd40919cc07c06168bd089eabd5236ceb70f596cf6119d94d6dff5f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruval (0.1.1)
4
+ ruval (0.1.6)
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:
@@ -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
@@ -83,14 +86,23 @@ line_stack = []
83
86
  scope = []
84
87
 
85
88
  File.read(file).each_line do |l|
89
+ next if(comment?(l) || l.strip.empty?)
86
90
  update_scope(l, line_stack, scope)
87
- next if(comment?(l) || l.strip.empty? || !scope.empty?)
91
+ next unless scope.empty?
88
92
  l = if line_stack.empty?
89
- line_spacing == 0 ? l.remove_comments(longest) : l
93
+ opts[:line_spacing] == 0 ? l.remove_comments(longest) : l
90
94
  else
91
- line_stack.join
95
+ line_stack.slice!(0,line_stack.length).join
92
96
  end
93
- line_stack = []
94
- puts l + "=> #{eval l, TOPLEVEL_BINDING}" + "\n"*line_spacing
97
+ value = eval(l, TOPLEVEL_BINDING)
98
+ value = if value.class == String
99
+ "\"#{value}\""
100
+ elsif value.class == Symbol
101
+ ":#{value}"
102
+ else
103
+ value
104
+ end
105
+ color = opts[:colorize] ? "\e[32m" : "\e[m"
106
+ puts l + "#{color}=> #{value}\e[m" + "\n" * opts[:line_spacing]
95
107
  end
96
108
 
@@ -1,3 +1,3 @@
1
1
  module Ruval
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.6"
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.1
4
+ version: 0.1.6
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: []