class Transpec::Syntax::Its::AttributeExpression
Attributes
node[R]
Public Class Methods
new(node)
click to toggle source
# File lib/transpec/syntax/its.rb, line 128 def initialize(node) @node = node end
Public Instance Methods
attributes()
click to toggle source
# File lib/transpec/syntax/its.rb, line 140 def attributes @attributes ||= if brackets? brackets_attributes else non_brackets_attributes end end
brackets?()
click to toggle source
# File lib/transpec/syntax/its.rb, line 132 def brackets? node.array_type? end
literal?()
click to toggle source
# File lib/transpec/syntax/its.rb, line 136 def literal? Util.literal?(node) end
Private Instance Methods
brackets_attributes()
click to toggle source
# File lib/transpec/syntax/its.rb, line 150 def brackets_attributes selector = node.loc.expression.source description = literal? ? quote(selector) : selector [Attribute.new(selector, description)] end
non_brackets_attributes()
click to toggle source
# File lib/transpec/syntax/its.rb, line 156 def non_brackets_attributes if literal? expression = node.children.first.to_s chained_names = expression.split('.') chained_names.map do |name| Attribute.new(".#{name}", quote("##{name}")) end else source = node.loc.expression.source selector = ".send(#{source})" [Attribute.new(selector, source)] end end
quote(string)
click to toggle source
# File lib/transpec/syntax/its.rb, line 170 def quote(string) if string.include?("'") '"' + string + '"' elsif string.include?('"') string.inspect else "'" + string + "'" end end