Class: HashMapper::PathMap

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hash_mapper.rb

Overview

contains array of path segments

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#inject_with_index

Constructor Details

#initialize(path) ⇒ PathMap

Returns a new instance of PathMap.



211
212
213
214
215
216
# File 'lib/hash_mapper.rb', line 211

def initialize(path)
  @path = path.dup
  @segments = parse(path)
  @filter = lambda{|value| value}# default filter does nothing
  @filter_arity = 1
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



209
210
211
# File 'lib/hash_mapper.rb', line 209

def path
  @path
end

#segmentsObject (readonly)

Returns the value of attribute segments.



208
209
210
# File 'lib/hash_mapper.rb', line 208

def segments
  @segments
end

Instance Method Details

#apply_filter(value, context: nil) ⇒ Object



223
224
225
226
227
# File 'lib/hash_mapper.rb', line 223

def apply_filter(value, context: nil)
  args = [value]
  args << context if @filter_arity > 1
  @filter.call(*args)
end

#each(&blk) ⇒ Object



229
230
231
# File 'lib/hash_mapper.rb', line 229

def each(&blk)
  @segments.each(&blk)
end

#filter=(f) ⇒ Object



218
219
220
221
# File 'lib/hash_mapper.rb', line 218

def filter=(f)
  @filter_arity = f.respond_to?(:arity) ? f.arity : 1
  @filter = f
end

#firstObject



233
234
235
# File 'lib/hash_mapper.rb', line 233

def first
  @segments.first
end

#lastObject



237
238
239
# File 'lib/hash_mapper.rb', line 237

def last
  @segments.last
end

#sizeObject



241
242
243
# File 'lib/hash_mapper.rb', line 241

def size
  @segments.size
end