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.



215
216
217
218
219
220
# File 'lib/hash_mapper.rb', line 215

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.



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

def path
  @path
end

#segmentsObject (readonly)

Returns the value of attribute segments.



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

def segments
  @segments
end

Instance Method Details

#apply_filter(value, context: nil) ⇒ Object



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

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

#each(&blk) ⇒ Object



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

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

#filter=(f) ⇒ Object



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

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

#firstObject



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

def first
  @segments.first
end

#lastObject



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

def last
  @segments.last
end

#sizeObject



245
246
247
# File 'lib/hash_mapper.rb', line 245

def size
  @segments.size
end