ruby.py 0.1.0 → 0.2.0

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: 23e4777e192552f8a73833c19ecf57fbee93a7e5a7139418b127c805c9ce9900
4
- data.tar.gz: f2306d60c29f6fab2ed1567c117bbb0661461fcfaca4d3f5a36a50d628fc3e79
3
+ metadata.gz: 51fbf865ea74599bda5ab70dae81134f7a4b776d79f22c6403a45ed4b52406b4
4
+ data.tar.gz: 51333e3fb78c9145f33d577530e7f6e222890f2862d3e9fbb588d0ef11322c46
5
5
  SHA512:
6
- metadata.gz: 18832b3dc32b33998421e82ad936423f9e33b8e530577b3df98eca8fb3b7913081dcab750cb13b62d66c0aa662b7ee02b0c04a3a319c6aa547a2e7ebefa7136d
7
- data.tar.gz: b4c169ddb231cf56779f0c60e6bedc431ba5600f6806db828c1845757683cb7aeb36d58e3dca635c8de1860ba1514c27d1971ca21673caca18407ad7821c0edd
6
+ metadata.gz: '08aaa5b7f566c4333c03e8bc68317643180d9dc70630642a054b785fd2e3a6b5a9a6012e36417761db078c38ff4508d83eae3c2bc1295b7dd6c43a88d3de7a76'
7
+ data.tar.gz: c0b202b80f8ce8f9ec31dced79046d755097bd5ec8c7532578ec156d65f6eec6d3289c6b5183e310b97f20d865bcbbb349c8f327d2f4ba3bd5ca1ac18110cb21
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby.py (0.1.0)
4
+ ruby.py (0.2.0)
5
5
  pycall
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -23,10 +23,32 @@ Or install it yourself as:
23
23
  ```ruby
24
24
  require 'ruby.py'
25
25
 
26
+ string = RubyPy.import('string')
27
+ string.Formatter.new.format('The sum of 1 + 2 is {0}', 3)
28
+ #=> 'The sum of 1 + 2 is 3'
29
+ string.Template.new('$subject $object $verb')
30
+ .substitute(subject: 'S', object: 'O', verb: 'V')
31
+ #=> 'S O V'
32
+ string.capwords('this is a test')
33
+ #=> 'This Is A Test'
34
+
35
+ re = RubyPy.import('re')
36
+ m = re.match('(\w+) (\w+)', 'Isaac Newton, physicist')
37
+ m.group(0) #=> 'Isaac Newton'
38
+ m.group(1) #=> 'Isaac'
39
+ m.group(2) #=> 'Newton'
40
+ m.group(1, 2) #=> PyCall::Tuple.call(%w[Isaac Newton])
41
+
26
42
  cv2 = RubyPy.import('cv2')
27
43
  cv2.imread('example.png')
28
44
 
29
45
  np = RubyPy.import('numpy')
46
+ a = np.arange(15).reshape(3, 5)
47
+ a.shape.inspect #=> '(3, 5)'
48
+ a.ndim #=> 2
49
+ a.dtype.name #=> 'int64'
50
+ a.itemsize #=> 8
51
+ a.size #=> 15
30
52
 
31
53
  tf = RubyPy.import('tensorflow')
32
54
  sess = tf.Session.call
@@ -1,8 +1,14 @@
1
+ # rubocop:disable Metrics/AbcSize
2
+ # rubocop:disable Security/Eval
3
+ # rubocop:disable Style/EvalWithLocation
4
+
1
5
  require 'pycall/import'
2
6
 
3
7
  # Ruby wrapper for Python modules.
4
8
  module RubyPy
5
9
  def self.import(pym)
10
+ raise ArgumentError unless pym =~ /\A[-_.A-Za-z0-9]+\Z/
11
+
6
12
  mod = pym.split('.').map { |s| s.split('_').map(&:capitalize).join }
7
13
  mod.size.times { |i| eval "module #{mod[0..i].join('::')}; end" }
8
14
 
@@ -24,10 +30,14 @@ module RubyPy
24
30
  def self.respond_to_missing?(method_name, include_private = false)
25
31
  @pycall.import.respond_to?(method_name, include_private)
26
32
  end
27
- end
33
+ end
28
34
 
29
- self
35
+ self
30
36
  end
31
37
  EVAL
32
38
  end
33
39
  end
40
+
41
+ # rubocop:enable Style/EvalWithLocation
42
+ # rubocop:enable Security/Eval
43
+ # rubocop:enable Metrics/AbcSize
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'ruby.py'
6
- spec.version = '0.1.0'
6
+ spec.version = '0.2.0'
7
7
  spec.authors = ['Frank J. Cameron']
8
8
  spec.email = ['fjc@fastmail.net']
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby.py
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank J. Cameron
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2018-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler