Class: NodeTextifier
- Inherits:
- 
      Object
      
        - Object
- NodeTextifier
 
- Defined in:
- lib/rails5/spec_converter/node_textifier.rb
Instance Method Summary collapse
- 
  
    
      #initialize(content)  ⇒ NodeTextifier 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of NodeTextifier. 
- #node_to_string(node) ⇒ Object
- #text_after_last_pair(hash_node) ⇒ Object
- #text_before_first_pair(hash_node) ⇒ Object
- #text_before_node(node) ⇒ Object
- #text_between_siblings(node1, node2) ⇒ Object
Constructor Details
#initialize(content) ⇒ NodeTextifier
Returns a new instance of NodeTextifier.
| 2 3 4 | # File 'lib/rails5/spec_converter/node_textifier.rb', line 2 def initialize(content) @content = content end | 
Instance Method Details
#node_to_string(node) ⇒ Object
| 25 26 27 | # File 'lib/rails5/spec_converter/node_textifier.rb', line 25 def node_to_string(node) @content[node.loc.expression.begin_pos...node.loc.expression.end_pos] end | 
#text_after_last_pair(hash_node) ⇒ Object
| 10 11 12 | # File 'lib/rails5/spec_converter/node_textifier.rb', line 10 def text_after_last_pair(hash_node) @content[hash_node.children.last.loc.expression.end_pos...hash_node.loc.expression.end_pos] end | 
#text_before_first_pair(hash_node) ⇒ Object
| 6 7 8 | # File 'lib/rails5/spec_converter/node_textifier.rb', line 6 def text_before_first_pair(hash_node) @content[hash_node.loc.expression.begin_pos...hash_node.children.first.loc.expression.begin_pos] end | 
#text_before_node(node) ⇒ Object
| 14 15 16 17 18 19 | # File 'lib/rails5/spec_converter/node_textifier.rb', line 14 def text_before_node(node) previous_sibling = node.parent.children[node.sibling_index - 1] return nil unless previous_sibling.loc.expression text_between_siblings(previous_sibling, node) end | 
#text_between_siblings(node1, node2) ⇒ Object
| 21 22 23 | # File 'lib/rails5/spec_converter/node_textifier.rb', line 21 def text_between_siblings(node1, node2) @content[node1.loc.expression.end_pos...node2.loc.expression.begin_pos] end |