dsl-python 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79b4ff2a17e321801b7d0f6f1f0ede3803b05560caca9602c2d7d190483c3a81
4
- data.tar.gz: 4773c0bdc56d29aff9507ea1a9147abd566632b28088ed982e8882d9ce18d1ec
3
+ metadata.gz: d283abe3337a500dfb1f48ce1ad5f70dc9f3240d0f71cfc849a3e44263f05f52
4
+ data.tar.gz: 46ace9246375b35df8c1e14991fa24c0b87453b4324b4cdb7df96bc52f0dbbad
5
5
  SHA512:
6
- metadata.gz: ae9e7d3899600e11d18fe39f8f7e2013ff818c546598c0f8944dbf4374e152d7362a470cac93622dd878f884b353290967aa295b9cc1b52c4cf84dddb0835038
7
- data.tar.gz: c5be922b1ab00dc12affa16cd5cf9375a71507c183260f4873c5db9f5c2c6d964752db11803dffed1213bb51e9978f79c9f7c2c005523a06b3f7ed7430c14b7a
6
+ metadata.gz: 8e927692c4185435682f232c8181a9df5919cea7735606dfb2ac5cdceb79bef599f5bc5476e35837727e6d20739e1705a765d6f6149aaab9265fa1fd40e109cd
7
+ data.tar.gz: fc5419c36c4adb8af36c4fe4ac95e87e24fc867f0b243e424a2301fe09a9a09e99486599673c1668f89c559042082a3f6fdff90fabe10079300b80e9d38e62ad
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Dsl::Python
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/dsl-python.svg)](https://badge.fury.io/rb/dsl-python)
4
+ ![GitHub](https://img.shields.io/github/license/dvarrui/dsl-python)
5
+
3
6
  ```
4
7
  DSL para hacer que Ruby "parezca" Python
5
8
  ```
@@ -20,21 +23,22 @@ Crear un programa con el contenido de un programa Python:
20
23
  ```python
21
24
  name = "Obiwan Kwnobi"
22
25
  print(name)
23
- print(type(name)) #=> name is str class
26
+ print(type(name)) #=> <class 'str'>
24
27
 
25
28
  words = name.split()
26
- print(words)
27
- print(type(words)) #=> words is list class
29
+ print(words) #=> ["Obiwan", "Kenobi"]
30
+ print("_".join(words)) #=> "Obiwan_Kenobi"
28
31
  ```
29
32
 
30
33
  * Ejecutar con el "intérprete": `npython FILENAME`.
31
34
 
32
35
  ```bash
33
- $ npython examples/03-variables.py
34
- 4
35
- <class 'int'>
36
- Obiwan
36
+ $ npython examples/02-vars.py
37
+
38
+ Obiwan Kenobi
37
39
  <class 'str'>
40
+ ["Obiwan", "Kenobi"]
41
+ <class 'list'>
38
42
  ```
39
43
 
40
44
  > Más [ejemplos](./examples/)
@@ -49,6 +53,7 @@ Obiwan
49
53
  - None
50
54
  - Ranges
51
55
  - Strings: `join`.
56
+ - Tuples: `tuple(1, 'a')`
52
57
  * Funciones comunes: `id`, `len`, `type`
53
58
 
54
59
  ## Contributing
@@ -11,7 +11,8 @@ def type(x)
11
11
  NilClass: "NoneType",
12
12
  Range: "range",
13
13
  String: "str",
14
- TrueClass: "bool"
14
+ TrueClass: "bool",
15
+ Tuple: "tuple"
15
16
  }
16
17
 
17
18
  "<class '#{types[key]}'>"
@@ -8,7 +8,8 @@ class String
8
8
  def replace(a, b) = tr(a, b)
9
9
  def title = capitalize
10
10
  def upper = upcase
11
-
11
+ def __len__() = self.length
12
+
12
13
  def __
13
14
  names = %w[
14
15
  str.__add__( str.__getattribute__( str.__le__( str.__repr__()
@@ -23,4 +24,5 @@ class String
23
24
  ]
24
25
  Dsl::Python.puts_in_columns(names.sort)
25
26
  end
27
+
26
28
  end
@@ -0,0 +1,25 @@
1
+
2
+ # Tuple = Struct.new(:_1, :_2, :_3, :_4)
3
+
4
+ def tuple(*values)
5
+ t = Tuple.new
6
+ values.each { t << _1 }
7
+ t
8
+ end
9
+
10
+ class Tuple < Array
11
+ def to_ary
12
+ to_a
13
+ end
14
+
15
+ def to_s
16
+ items = self.map do
17
+ if _1.is_a?(String)
18
+ "'#{_1}'"
19
+ else
20
+ _1
21
+ end
22
+ end
23
+ "(#{items.join(", ")})"
24
+ end
25
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Dsl
4
4
  module Python
5
- VERSION = "0.20.0"
5
+ VERSION = "0.21.0"
6
6
  end
7
7
  end
8
8
 
data/lib/dsl/python.rb CHANGED
@@ -13,6 +13,7 @@ require_relative "python/types/integer"
13
13
  require_relative "python/types/none"
14
14
  require_relative "python/types/range"
15
15
  require_relative "python/types/string"
16
+ require_relative "python/types/tuple"
16
17
 
17
18
  require_relative "python/functions/etc"
18
19
  require_relative "python/functions/import"
@@ -23,9 +24,15 @@ require_relative "python/version"
23
24
  def print(*args)
24
25
  if args.is_a? Array
25
26
  if args.count == 1
26
- puts args.first
27
+ item = args.first
28
+ if item.is_a? Array
29
+ puts "#{item}"
30
+ else
31
+ puts item
32
+ end
27
33
  else
28
- puts args.join " "
34
+ text = args.map { _1.to_s }.join " "
35
+ puts text
29
36
  end
30
37
  else
31
38
  puts(args)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsl-python
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz
@@ -43,6 +43,7 @@ files:
43
43
  - lib/dsl/python/types/none.rb
44
44
  - lib/dsl/python/types/range.rb
45
45
  - lib/dsl/python/types/string.rb
46
+ - lib/dsl/python/types/tuple.rb
46
47
  - lib/dsl/python/version.rb
47
48
  homepage: https://github.com/dvarrui/dsl-python
48
49
  licenses: