Class: HashAtPath::Path
- Inherits:
-
Object
- Object
- HashAtPath::Path
- Defined in:
- lib/hash_at_path/path.rb
Class Method Summary collapse
-
.extract_path_data(path_string) ⇒ Object
Extracts paths and predicates from the provide full path.
- .parse(path_string) ⇒ Object
- .replace_predicates(path_string) ⇒ Object
Class Method Details
.extract_path_data(path_string) ⇒ Object
Extracts paths and predicates from the provide full path
16 17 18 19 |
# File 'lib/hash_at_path/path.rb', line 16 def extract_path_data(path_string) results = array_wrap(path_string.scan(/([^\[]*)(\[)*(\d|\-\d|\*)*(\])*/i)) results.map {|match| {:path => match[0], :predicate => match[2]}} end |
.parse(path_string) ⇒ Object
4 5 6 7 |
# File 'lib/hash_at_path/path.rb', line 4 def parse(path_string) path_string = replace_predicates(path_string) vals = extract_path_data(path_string) end |
.replace_predicates(path_string) ⇒ Object
9 10 11 12 13 |
# File 'lib/hash_at_path/path.rb', line 9 def replace_predicates(path_string) path_string.gsub!(/first\(\)/, "0") path_string.gsub!(/last\(\)/, "-1") path_string end |