Class: RegexpTree::Alt

Inherits:
RegexpTree show all
Defined in:
lib/regexptree.rb

Constant Summary

Constants inherited from RegexpTree

EmptySequence, EmptySet

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RegexpTree

#*, #+, alt, backref, charclass, #closure, #empty_sequence?, #group, inherited, #inspect, linebeg, lineend, #lookahead, #negative_lookahead, non_word_boundary, #nongreedy_closure, #nongreedy_ntimes, #nongreedy_optional, #nongreedy_positive_closure, #nongreedy_rep, #ntimes, #optional, #paren, #parenthesize, #positive_closure, #pretty_print, previous_match, #regexp, #rep, rep, seq, str, strbeg, strend, strlineend, #to_s, word_boundary, #|

Constructor Details

#initialize(rs) ⇒ Alt

Returns a new instance of Alt.



163
164
165
# File 'lib/regexptree.rb', line 163

def initialize(rs)
  @rs = rs
end

Instance Attribute Details

#rsObject (readonly)

Returns the value of attribute rs.



166
167
168
# File 'lib/regexptree.rb', line 166

def rs
  @rs
end

Instance Method Details

#case_insensitive?Boolean

Returns:

  • (Boolean)


172
173
174
# File 'lib/regexptree.rb', line 172

def case_insensitive?
  @rs.all? {|r| r.case_insensitive?}
end

#downcaseObject



180
181
182
# File 'lib/regexptree.rb', line 180

def downcase
  Alt.new(@rs.map {|r| r.downcase})
end

#empty_set?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/regexptree.rb', line 168

def empty_set?
  @rs.empty?
end

#multiline_insensitive?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/regexptree.rb', line 176

def multiline_insensitive?
  @rs.all? {|r| r.multiline_insensitive?}
end

#pretty_format(out) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/regexptree.rb', line 184

def pretty_format(out)
  if @rs.empty?
    out.text '(?!)'
  else
	out.group {
	  @rs.each_with_index {|r, i|
 unless i == 0
   out.text '|'
   out.breakable ''
 end
 r.parenthesize(Alt).pretty_format(out)
	  }
	}
  end
end