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)


49
50
51
52
# File 'lib/xdry/parsing/parts/selectors.rb', line 49

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.



47
48
49
# File 'lib/xdry/parsing/parts/selectors.rb', line 47

def arg_name
  @arg_name
end

#keywordObject (readonly)

Returns the value of attribute keyword.



47
48
49
# File 'lib/xdry/parsing/parts/selectors.rb', line 47

def keyword
  @keyword
end

#typeObject (readonly)

Returns the value of attribute type.



47
48
49
# File 'lib/xdry/parsing/parts/selectors.rb', line 47

def type
  @type
end

Instance Method Details

#has_type?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/xdry/parsing/parts/selectors.rb', line 58

def has_type?
  not @type.nil?
end

#keyword_without_colonObject



54
55
56
# File 'lib/xdry/parsing/parts/selectors.rb', line 54

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

#to_sObject



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

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