Class: Riml::ImportedClass

Inherits:
Object
  • Object
show all
Defined in:
lib/riml/imported_class.rb

Constant Summary collapse

ANCHOR_BEGIN =
'\A'
ANCHOR_END =
'\Z'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ImportedClass

Returns a new instance of ImportedClass.



10
11
12
# File 'lib/riml/imported_class.rb', line 10

def initialize(name)
  @name = rm_modifier(name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/riml/imported_class.rb', line 9

def name
  @name
end

Instance Method Details

#constructorObject

stubbed out constructor function



46
47
48
49
50
# File 'lib/riml/imported_class.rb', line 46

def constructor
  @contructor ||= begin
    DefNode.new('!', nil, scope_modifier, constructor_name, ['...'], [], Nodes.new([]))
  end
end

#constructor_nameObject



52
53
54
# File 'lib/riml/imported_class.rb', line 52

def constructor_name
  "#{@name}Constructor"
end

#constructor_obj_nameObject



56
57
58
# File 'lib/riml/imported_class.rb', line 56

def constructor_obj_name
  @name[0, 1].downcase + @name[1..-1] + "Obj"
end

#global_import?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/riml/imported_class.rb', line 37

def global_import?
  @name == '*'
end

#globbed?Boolean

an ImportedClass is #globbed? if its name contains 1 or more ‘*’ characters.

Returns:

  • (Boolean)


20
21
22
# File 'lib/riml/imported_class.rb', line 20

def globbed?
  not @name.index('*').nil?
end

#imported?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/riml/imported_class.rb', line 14

def imported?
  true
end

#match?(class_name) ⇒ Boolean

returns MatchData or ‘nil`

Returns:

  • (Boolean)


25
26
27
# File 'lib/riml/imported_class.rb', line 25

def match?(class_name)
  match_regexp.match(rm_modifier(class_name))
end

#match_regexpObject

returns Regexp



30
31
32
33
34
35
# File 'lib/riml/imported_class.rb', line 30

def match_regexp
  @match_regexp ||= begin
    normalized_glob = @name.gsub(/\*/, '.*?')
    Regexp.new(ANCHOR_BEGIN + normalized_glob + ANCHOR_END)
  end
end

#scope_modifierObject



41
42
43
# File 'lib/riml/imported_class.rb', line 41

def scope_modifier
  'g:'
end