Class: Comet::Reference

Inherits:
ReferenceBase show all
Defined in:
lib/comet-html/parser-reference.rb

Direct Known Subclasses

RemoteReference

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ReferenceBase

#has_default_value?, #has_getter?, #has_initializer?, #has_setter?

Constructor Details

#initialize(el, parent, mode = nil) ⇒ Reference

Returns a new instance of Reference.



53
54
55
56
57
58
59
# File 'lib/comet-html/parser-reference.rb', line 53

def initialize el, parent, mode = nil
  el["_cheerp_ref"] = self
  @el     = el
  @parent = parent
  @type   = @parent.context.find_cpp_type el.name
  set_mode mode
end

Instance Attribute Details

#elObject (readonly)

Returns the value of attribute el.



51
52
53
# File 'lib/comet-html/parser-reference.rb', line 51

def el
  @el
end

#nameObject (readonly)

Returns the value of attribute name.



51
52
53
# File 'lib/comet-html/parser-reference.rb', line 51

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



51
52
53
# File 'lib/comet-html/parser-reference.rb', line 51

def type
  @type
end

Instance Method Details

#is_explicit?Boolean

Returns:

  • (Boolean)


74
# File 'lib/comet-html/parser-reference.rb', line 74

def is_explicit? ; @mode == :explicit ; end

#is_implicit?Boolean

Returns:

  • (Boolean)


75
# File 'lib/comet-html/parser-reference.rb', line 75

def is_implicit? ; @mode == :implicit ; end

#set_mode(mode) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/comet-html/parser-reference.rb', line 61

def set_mode mode
  if (mode.nil? && !@el["ref"].nil?) || (mode == :explicit)
    @mode = :explicit
    @name = @el["ref"].to_s
    unless is_valid_cpp_variable_name?(@name)
      raise ParseError.new(el, "ref `#{@name}` is not a valid c++ variable name")
    end
  else
    @mode = :implicit
    @name = "element_#{@parent.context.generate_new_ref_name}"
  end
end