code-ruby 0.9.1 → 0.9.3

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: 1f92c4c4db84ee34d5e5d58325ab4de49d9346a738239aba44682db9e2530e7e
4
- data.tar.gz: 6d056953ec6852d7824343f45198e0b35f13db881420fdce645753e091249ac7
3
+ metadata.gz: fbab52af883b6728dd2be14b84df672b911f542bc1b46e5f905be43acf1c0aed
4
+ data.tar.gz: 266bfadcff8f8deffc940f1a802d97a2dc5b89a189233eda6418f0e6939798b2
5
5
  SHA512:
6
- metadata.gz: 98ddcc59fe93cf2625cbc521a08b2119bcb8fc1bd8cd6fd3da6fb40039a73aa8835e35234c3e77842fbbcc6fa57fe51377e96f457bfd6e391a5bd96d37229296
7
- data.tar.gz: 7b2723a4c912be64c3c7588fb905b40c6cd8fc510a61ca56a7af21037bd8d27d29a667659ea07a97d096d9a44d01dc6a5064f7a45ee58e39770d016a479353af
6
+ metadata.gz: 2503a5d2bfe52eb270c81156dfa40fa535427ff2222748344669f27cd069da453eb5d2ea506f01af8f5e210e51f89eaa80de5d0558539d38a14d714393d5b7b5
7
+ data.tar.gz: 455729dce33fe36792986541c6c78d3e53fad319728f141568f51d13b989d0da648422c69cb623c9ab327679610150c0bf06eefc9caf0a740b86c3d5de79700a
data/bin/code CHANGED
@@ -9,15 +9,14 @@ options = {
9
9
  profile: false,
10
10
  profiler: "text",
11
11
  input: "",
12
- context: "",
13
12
  parse: false
14
13
  }
15
14
 
16
- OptionParser
15
+ argv = OptionParser
17
16
  .new do |opts|
18
- opts.banner = "Usage: code [options]"
17
+ opts.banner = "Usage: code INPUT\n\n"
19
18
 
20
- opts.on("-v", "--version", "Version of template") do |_input|
19
+ opts.on("-v", "--version", "Version of Code") do |_input|
21
20
  puts Code::Version
22
21
  exit
23
22
  end
@@ -25,24 +24,14 @@ OptionParser
25
24
  opts.on(
26
25
  "-i INPUT",
27
26
  "--input INPUT",
28
- "Input in the code language (String or File)"
27
+ "Input in the Code language (String or File)"
29
28
  ) do |input|
30
29
  input = File.read(input) if File.exist?(input)
31
30
 
32
31
  options[:input] = input
33
32
  end
34
33
 
35
- opts.on(
36
- "-c CONTEXT",
37
- "--context CONTEXT",
38
- "Context in the code language (String or File)"
39
- ) do |context|
40
- context = File.read(context) if File.exist?(context)
41
-
42
- options[:context] = context
43
- end
44
-
45
- opts.on("-p", "--parse", "Get parser results for input") do |parse|
34
+ opts.on("-p", "--parse", "Parser tree for input") do |parse|
46
35
  options[:parse] = parse
47
36
  end
48
37
 
@@ -68,6 +57,21 @@ OptionParser
68
57
  end
69
58
  .parse!
70
59
 
60
+ options[:input] = argv.join(" ") if options[:input].empty?
61
+
62
+ if options[:input].empty?
63
+ abort <<~HELP
64
+ Usage: code INPUT
65
+
66
+ -v, --version Version of Code
67
+ -i, --input INPUT Input in the Code language (String or File)
68
+ -p, --parse Parser tree for input
69
+ -t, --timeout TIMEOUT Set timeout in seconds
70
+ --profile Profile Ruby code
71
+ --profiler TYPE Profiler output type (text (default) or html)
72
+ HELP
73
+ end
74
+
71
75
  RubyProf.start if options[:profile]
72
76
 
73
77
  if options[:parse]
@@ -75,7 +79,6 @@ if options[:parse]
75
79
  else
76
80
  print Code.evaluate(
77
81
  options[:input],
78
- options[:context],
79
82
  output: $stdout,
80
83
  error: $stderr,
81
84
  timeout: options[:timeout]
@@ -6,7 +6,11 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(raw)
9
- @raw = raw
9
+ if raw.is_a?(Object)
10
+ @raw = raw.truthy?
11
+ else
12
+ @raw = !!raw
13
+ end
10
14
  end
11
15
 
12
16
  def self.name
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(raw)
9
+ raw = raw.raw if raw.is_a?(Class)
9
10
  @raw = raw
10
11
  end
11
12
 
@@ -6,7 +6,8 @@ class Code
6
6
  attr_reader :parent
7
7
 
8
8
  def initialize(raw = {}, parent: nil)
9
- @raw = raw
9
+ raw = raw.raw if raw.is_a?(Dictionary)
10
+ @raw = raw.to_h
10
11
  @parent = parent
11
12
  end
12
13
 
@@ -6,7 +6,8 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(date)
9
- @raw = date
9
+ date = date.raw if date.is_a?(Date)
10
+ @raw = date.to_date
10
11
  end
11
12
 
12
13
  def self.name
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(decimal, exponent: nil)
9
+ decimal = decimal.raw if decimal.is_a?(Decimal)
9
10
  @raw = BigDecimal(decimal)
10
11
 
11
12
  return unless exponent
@@ -6,7 +6,8 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(raw = {})
9
- @raw = raw
9
+ raw = raw.raw if raw.is_a?(Dictionary)
10
+ @raw = raw.to_h
10
11
  end
11
12
 
12
13
  def self.name
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(duration)
9
+ duration = duration.raw if duration.is_a?(Duration)
9
10
  @raw = duration
10
11
  end
11
12
 
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(raw = [])
9
+ raw = raw.raw if raw.is_a?(List)
9
10
  @raw = raw.to_a
10
11
  end
11
12
 
@@ -8,7 +8,7 @@ class Code
8
8
  def initialize(left, right, exclude_end: false)
9
9
  @left = left
10
10
  @right = right
11
- @exclude_end = exclude_end
11
+ @exclude_end = !!exclude_end
12
12
  @raw = ::Range.new(left, right, exclude_end)
13
13
  end
14
14
 
@@ -6,6 +6,7 @@ class Code
6
6
  attr_reader :raw
7
7
 
8
8
  def initialize(string)
9
+ string = string.raw if string.is_a?(String)
9
10
  @raw = string.to_s
10
11
  end
11
12
 
data/lib/code/version.rb CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative "../code"
4
4
 
5
- Code::Version = Gem::Version.new("0.9.1")
5
+ Code::Version = Gem::Version.new("0.9.3")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié