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 +4 -4
- data/README.md +12 -7
- data/lib/dsl/python/functions/type.rb +2 -1
- data/lib/dsl/python/types/string.rb +3 -1
- data/lib/dsl/python/types/tuple.rb +25 -0
- data/lib/dsl/python/version.rb +1 -1
- data/lib/dsl/python.rb +9 -2
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d283abe3337a500dfb1f48ce1ad5f70dc9f3240d0f71cfc849a3e44263f05f52
|
|
4
|
+
data.tar.gz: 46ace9246375b35df8c1e14991fa24c0b87453b4324b4cdb7df96bc52f0dbbad
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e927692c4185435682f232c8181a9df5919cea7735606dfb2ac5cdceb79bef599f5bc5476e35837727e6d20739e1705a765d6f6149aaab9265fa1fd40e109cd
|
|
7
|
+
data.tar.gz: fc5419c36c4adb8af36c4fe4ac95e87e24fc867f0b243e424a2301fe09a9a09e99486599673c1668f89c559042082a3f6fdff90fabe10079300b80e9d38e62ad
|
data/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Dsl::Python
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/dsl-python)
|
|
4
|
+

|
|
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))
|
|
26
|
+
print(type(name)) #=> <class 'str'>
|
|
24
27
|
|
|
25
28
|
words = name.split()
|
|
26
|
-
print(words)
|
|
27
|
-
print(
|
|
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/
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
@@ -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
|
data/lib/dsl/python/version.rb
CHANGED
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
|
-
|
|
27
|
+
item = args.first
|
|
28
|
+
if item.is_a? Array
|
|
29
|
+
puts "#{item}"
|
|
30
|
+
else
|
|
31
|
+
puts item
|
|
32
|
+
end
|
|
27
33
|
else
|
|
28
|
-
|
|
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.
|
|
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:
|