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
-
#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, context: nil) ⇒ Object
- #each(&blk) ⇒ Object
- #filter=(f) ⇒ 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.
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
#path ⇒ Object (readonly)
Returns the value of attribute path.
209 210 211 |
# File 'lib/hash_mapper.rb', line 209 def path @path end |
#segments ⇒ Object (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 |
#first ⇒ Object
233 234 235 |
# File 'lib/hash_mapper.rb', line 233 def first @segments.first end |
#last ⇒ Object
237 238 239 |
# File 'lib/hash_mapper.rb', line 237 def last @segments.last end |
#size ⇒ Object
241 242 243 |
# File 'lib/hash_mapper.rb', line 241 def size @segments.size end |