Class: XDry::SelectorComponent

Inherits:
Object
  • Object
show all
Defined in:
lib/xdry/parsing/parts/selectors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword, arg_name, type) ⇒ SelectorComponent

Returns a new instance of SelectorComponent.

Raises:

  • (StandardError)


67
68
69
70
# File 'lib/xdry/parsing/parts/selectors.rb', line 67

def initialize keyword, arg_name, type
  raise StandardError, "keyword must end with a colon: '#{keyword}'" unless keyword[-1] == ?:
  @keyword, @arg_name, @type = keyword, arg_name, type
end

Instance Attribute Details

#arg_nameObject (readonly)

Returns the value of attribute arg_name.



65
66
67
# File 'lib/xdry/parsing/parts/selectors.rb', line 65

def arg_name
  @arg_name
end

#keywordObject (readonly)

Returns the value of attribute keyword.



65
66
67
# File 'lib/xdry/parsing/parts/selectors.rb', line 65

def keyword
  @keyword
end

#typeObject (readonly)

Returns the value of attribute type.



65
66
67
# File 'lib/xdry/parsing/parts/selectors.rb', line 65

def type
  @type
end

Instance Method Details

#has_type?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/xdry/parsing/parts/selectors.rb', line 76

def has_type?
  not @type.nil?
end

#keyword_without_colonObject



72
73
74
# File 'lib/xdry/parsing/parts/selectors.rb', line 72

def keyword_without_colon
  @keyword_without_colon ||= @keyword.sub(/:$/, '')
end

#to_sObject



80
81
82
83
84
85
86
# File 'lib/xdry/parsing/parts/selectors.rb', line 80

def to_s
  if has_type?
    "#{keyword}(#{@type})#{@arg_name}"
  else
    "#{keyword}#{@arg_name}"
  end
end