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.



177
178
179
180
181
# File 'lib/hash_mapper.rb', line 177

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

Instance Attribute Details

#filter=(value) ⇒ Object (writeonly)

Sets the attribute filter

Parameters:

  • value

    the value to set the attribute filter to.



175
176
177
# File 'lib/hash_mapper.rb', line 175

def filter=(value)
  @filter = value
end

#segmentsObject (readonly)

Returns the value of attribute segments.



174
175
176
# File 'lib/hash_mapper.rb', line 174

def segments
  @segments
end

Instance Method Details

#apply_filter(value) ⇒ Object



183
184
185
# File 'lib/hash_mapper.rb', line 183

def apply_filter(value)
  @filter.call(value)
end

#each(&blk) ⇒ Object



187
188
189
# File 'lib/hash_mapper.rb', line 187

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

#firstObject



191
192
193
# File 'lib/hash_mapper.rb', line 191

def first
  @segments.first
end

#lastObject



195
196
197
# File 'lib/hash_mapper.rb', line 195

def last
  @segments.last
end

#sizeObject



199
200
201
# File 'lib/hash_mapper.rb', line 199

def size
  @segments.size
end