Class: Uttk::Logger::Path
- Extended by:
- Forwardable
- Defined in:
- lib/uttk/logger/path.rb
Overview
class Segment
Instance Method Summary collapse
- #+(rhs) ⇒ Object
- #<<(seg) ⇒ Object
- #==(rhs) ⇒ Object
-
#initialize(anArray = []) ⇒ Path
constructor
A new instance of Path.
- #initialize_copy(rhs) ⇒ Object
- #inspect ⇒ Object
- #lpath_prefix(re) ⇒ Object
- #rpath(re, &block) ⇒ Object
- #rpath_prefix(re) ⇒ Object
- #to_a ⇒ Object
- #to_logger_path ⇒ Object
- #to_regex_path ⇒ Object
- #to_regex_path_string ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(anArray = []) ⇒ Path
Returns a new instance of Path.
37 38 39 40 |
# File 'lib/uttk/logger/path.rb', line 37 def initialize ( anArray=[] ) @contents = [] anArray.each { |x| self << x } end |
Instance Method Details
#+(rhs) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/uttk/logger/path.rb', line 66 def + ( rhs ) if rhs.is_a? Path tab = rhs.instance_variable_get(:@contents) else tab = rhs.to_a end self.class.new(@contents + tab) end |
#<<(seg) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/uttk/logger/path.rb', line 52 def << ( seg ) @contents << case seg when Segment then seg else Segment.new seg end end |
#==(rhs) ⇒ Object
176 177 178 |
# File 'lib/uttk/logger/path.rb', line 176 def == ( rhs ) rhs.is_a?(self.class) && @contents == rhs.instance_variable_get(:@contents) end |
#initialize_copy(rhs) ⇒ Object
42 43 44 |
# File 'lib/uttk/logger/path.rb', line 42 def initialize_copy ( rhs ) @contents = rhs.instance_variable_get(:@contents).map { |x| x.dup } end |
#inspect ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/uttk/logger/path.rb', line 81 def inspect return '/' if @contents.empty? result = '' each do |seg| result << '/' << seg.quoted_segment unless seg..empty? opts = [] opts << 'ordered' if seg.[:ordered] if type = seg.[:type] opts << "type: #{type}" end result << '[' << opts.join(', ') << ']' end end result end |
#lpath_prefix(re) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/uttk/logger/path.rb', line 158 def lpath_prefix ( re ) re_segs = re.segments re_segs.zip(to_a).each_with_index do |args, i| re_seg, seg = args return true if seg.nil? return false unless re_seg =~ seg.to_s re_seg = re_segs[i+1] return true if re_seg and re_seg.captured? end raise ArgumentError, 'no capture' end |
#rpath(re, &block) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/uttk/logger/path.rb', line 108 def rpath ( re, &block ) # We work with uncaptured path here args = [] raise NotImplementedError unless re.root? or re.final? re_segs = re.segments segs = to_a if re.final? re_segs = re_segs.reverse segs = segs.reverse end re_segs.zip(segs).each do |re_seg, seg| if re.negative? break if seg.nil? or re_seg !~ seg.to_s return else return if seg.nil? if match_data = re_seg =~ seg.to_s args << match_data.to_a[1..-1] else return end end end args.reverse! if re.final? block[self, *args.flatten] nil end |
#rpath_prefix(re) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/uttk/logger/path.rb', line 144 def rpath_prefix ( re ) re_segs = re.segments re_segs.zip(to_a).each_with_index do |args, i| re_seg, seg = args return false if seg.nil? return false unless re_seg =~ seg.to_s re_seg = re_segs[i+1] return true if re_seg and re_seg.captured? end raise ArgumentError, 'no capture' end |
#to_a ⇒ Object
61 62 63 |
# File 'lib/uttk/logger/path.rb', line 61 def to_a map { |x| x.segment } end |
#to_logger_path ⇒ Object
172 173 174 |
# File 'lib/uttk/logger/path.rb', line 172 def to_logger_path self end |
#to_regex_path ⇒ Object
103 104 105 |
# File 'lib/uttk/logger/path.rb', line 103 def to_regex_path RegexPath.new(to_regex_path_string) end |
#to_regex_path_string ⇒ Object
98 99 100 |
# File 'lib/uttk/logger/path.rb', line 98 def to_regex_path_string '/' + map { |x| x.regexp_quoted_segment }.join('/') end |
#to_s ⇒ Object
76 77 78 |
# File 'lib/uttk/logger/path.rb', line 76 def to_s '/' + map { |x| x.quoted_segment }.join('/') end |