Class: HashMapper::PathMap
- Inherits:
-
Object
- Object
- HashMapper::PathMap
- Includes:
- Enumerable
- Defined in:
- lib/hash_mapper.rb
Overview
contains array of path segments
Instance Attribute Summary collapse
-
#filter ⇒ Object
writeonly
Sets the attribute filter.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Instance Method Summary collapse
- #apply_filter(value) ⇒ Object
- #each(&blk) ⇒ Object
- #first ⇒ Object
-
#initialize(path) ⇒ PathMap
constructor
A new instance of PathMap.
- #last ⇒ Object
- #size ⇒ Object
Methods included from Enumerable
Constructor Details
#initialize(path) ⇒ PathMap
Returns a new instance of PathMap.
198 199 200 201 202 |
# File 'lib/hash_mapper.rb', line 198 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
195 196 197 |
# File 'lib/hash_mapper.rb', line 195 def filter=(value) @filter = value end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
196 197 198 |
# File 'lib/hash_mapper.rb', line 196 def path @path end |
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
194 195 196 |
# File 'lib/hash_mapper.rb', line 194 def segments @segments end |
Instance Method Details
#apply_filter(value) ⇒ Object
204 205 206 |
# File 'lib/hash_mapper.rb', line 204 def apply_filter(value) @filter.call(value) end |
#each(&blk) ⇒ Object
208 209 210 |
# File 'lib/hash_mapper.rb', line 208 def each(&blk) @segments.each(&blk) end |
#first ⇒ Object
212 213 214 |
# File 'lib/hash_mapper.rb', line 212 def first @segments.first end |
#last ⇒ Object
216 217 218 |
# File 'lib/hash_mapper.rb', line 216 def last @segments.last end |
#size ⇒ Object
220 221 222 |
# File 'lib/hash_mapper.rb', line 220 def size @segments.size end |