Class: Yadriggy::Py::Import

Inherits:
Object
  • Object
show all
Defined in:
lib/yadriggy/py/import.rb

Overview

The import statement in Python.

Constant Summary collapse

@@src =
''
@@state =
0

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(name) ⇒ Object

from keyword.

Parameters:

  • name (String|Symbol)

    a module name.



58
59
60
61
62
63
# File 'lib/yadriggy/py/import.rb', line 58

def self.from(name)
  error('from') if @@state == 3
  @@src << "\nfrom " << name.to_s
  @@state = 3
  Import.new
end

.import(name) ⇒ Object

import keyword.

Parameters:

  • name (String|Symbol)

    a module name.



49
50
51
52
53
54
# File 'lib/yadriggy/py/import.rb', line 49

def self.import(name)
  error('import') if @@state == 3
  @@src << "\nimport " << name.to_s
  @@state = 1
  Import.new
end

Instance Method Details

#as(name) ⇒ Object

as keyword.

Parameters:

  • name (String|Symbol)

    an alias.



37
38
39
40
41
42
43
44
45
# File 'lib/yadriggy/py/import.rb', line 37

def as(name)
  if @@state == 1
    @@src << ' as ' << name.to_s
    @@state = 2
  else
    Import.error('as')
  end
  self
end

#import(name) ⇒ Object

import keyword.

Parameters:

  • name (String|Symbol)

    a module name etc.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yadriggy/py/import.rb', line 22

def import(name)
  if @@state == 1 || @@state == 2
    @@src << ', ' << name.to_s
    @@state = 1
  elsif @@state == 3
    @@src << ' import ' << name.to_s
    @@state = 1
  else
    Import.error('import')
  end
  self
end