Class: Y2R::AST::Ruby::HashEntry

Inherits:
Node
  • Object
show all
Defined in:
lib/y2r/ast/ruby.rb

Constant Summary

Constants inherited from Node

Node::INDENT_STEP

Instance Method Summary collapse

Methods inherited from Node

#ensure_separated, #has_comment?, #hates_to_stand_alone?, #single_line_width, #to_ruby

Instance Method Details

#ends_with_comment?Boolean

Returns:

  • (Boolean)


1653
1654
1655
# File 'lib/y2r/ast/ruby.rb', line 1653

def ends_with_comment?
  comment_after || value.ends_with_comment?
end

#key_width(context) ⇒ Object



1661
1662
1663
# File 'lib/y2r/ast/ruby.rb', line 1661

def key_width(context)
  key.to_ruby_base(context).split("\n").last.size
end

#pass_trailer?Boolean

Returns:

  • (Boolean)


1657
1658
1659
# File 'lib/y2r/ast/ruby.rb', line 1657

def pass_trailer?
  true
end

#priorityObject



1645
1646
1647
# File 'lib/y2r/ast/ruby.rb', line 1645

def priority
  Priority::ATOMIC
end

#single_line_width_base(context) ⇒ Object



1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
# File 'lib/y2r/ast/ruby.rb', line 1632

def single_line_width_base(context)
  if !has_line_breaking_comment?
    inner_context = context.with_priority(Priority::NONE)

    key_width   = key.single_line_width(inner_context)
    value_width = value.single_line_width(inner_context)

    key_width + 4 + value_width
  else
    Float::INFINITY
  end
end

#starts_with_comment?Boolean

Returns:

  • (Boolean)


1649
1650
1651
# File 'lib/y2r/ast/ruby.rb', line 1649

def starts_with_comment?
  comment_before || key.starts_with_comment?
end

#to_ruby_base(context) ⇒ Object



1624
1625
1626
1627
1628
1629
1630
# File 'lib/y2r/ast/ruby.rb', line 1624

def to_ruby_base(context)
  if !has_line_breaking_comment?
    to_ruby_base_single_line(context)
  else
    to_ruby_base_multi_line(context)
  end
end