hash_at_path 0.1.1 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8a4bc93281f59d57fbf0a460b3a04f37afec511a
4
- data.tar.gz: f5d83ef53445f9e17292a6ddffe740e16bd43ba0
2
+ SHA256:
3
+ metadata.gz: 4d9f5b0a2917bdf1119fcbde29bc0553d0b129d05cd37a8300e5444d647877be
4
+ data.tar.gz: ff184eb411d56d2075557fa35ef47c2c110d05a2735ea4cde1405eb484d7bc9b
5
5
  SHA512:
6
- metadata.gz: 86b1eb02e4616f284d429cc9b829313909afc124b8556631862b23e476b90cadd477117876f21b8611ffc336e735865d6ea9edeb95dd2ec92fc5825a3dca39a8
7
- data.tar.gz: 6fd325ca3b3cdd7dc2752467e26bd4e9cadd0123b6f03a8e2b991d0eb362122157904324b4c779b272ad7a5056204527fc032c970e64564ed61cbdb6f4207dce
6
+ metadata.gz: 6b9ffdfd6f03a658740e170eb474bfe49973b29be63ec5de545a8f797d6cd8b354c8a6527816cd0d8473ac9b0e00772893067c21ccf0a9fa1962eca8d199ddde
7
+ data.tar.gz: 5c33bba88b68c4d908459af8d112b5f8022cd0ec3b7482e05c3c10015fd6653229cf50cebce6cf76099c4e6e7b565d4f7fd74cfeb7262553e0bd5ed903a15f27
@@ -1,8 +1,10 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.2.2
5
- - 2.1.0
6
- - rbx-2.2.10
4
+ - 2.4.1
5
+ - 2.3.4
7
6
  - jruby-head
8
7
  - ruby-head
8
+ before_install: # For jruby-head to work.
9
+ - gem install bundler
10
+ - gem update bundler
@@ -1,23 +1,26 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'hash_at_path/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "hash_at_path"
8
+ spec.name = 'hash_at_path'
8
9
  spec.version = HashAtPath::VERSION
9
- spec.authors = ["chadfennell"]
10
- spec.email = ["libsys@gmail.com"]
10
+ spec.authors = ['chadfennell']
11
+ spec.email = ['libsys@gmail.com']
11
12
 
12
- spec.summary = %q{Extends Hash with xpath like syntax for retrieving hash values.}
13
- spec.homepage = "https://github.com/UMNLibraries/hash_at_path"
14
- spec.license = "MIT"
13
+ spec.summary = 'Extends Hash with xpath like syntax for retrieving hash values.'
14
+ spec.homepage = 'https://github.com/UMNLibraries/hash_at_path'
15
+ spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = "exe"
18
+ spec.bindir = 'exe'
18
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = '>= 2.1'
20
23
 
21
- spec.add_development_dependency "rake", "~> 10.0"
22
- spec.add_development_dependency "rspec", "~> 3.1"
24
+ spec.add_development_dependency 'rake', '>= 12.3.3'
25
+ spec.add_development_dependency 'rspec', '~> 3.1'
23
26
  end
@@ -4,7 +4,6 @@ module HashAtPath
4
4
  module AtPath
5
5
  # Returns a value at the end of an xpath-like/lite path
6
6
  def at_path(path)
7
- out = {}
8
7
  if path == '/'
9
8
  self
10
9
  else
@@ -20,16 +19,16 @@ module HashAtPath
20
19
  return nil if val.nil?
21
20
  predicate = path_parts[:predicate] unless predicate == '*'
22
21
  val, predicate = get_value_at_path(predicate, path_parts[:path], val)
23
- val = val[predicate.to_i] unless blank?(predicate) || predicate == '*' || !issa(val, 'Array')
22
+ val = val[predicate.to_i] unless is_blank?(predicate) || predicate == '*' || !issa(val, 'Array')
24
23
  end
25
24
  val
26
25
  end
27
26
 
28
27
  def get_value_at_path(predicate, path, val)
29
- if predicate == '*' && issa(val, 'Array') && !blank?(path)
28
+ if predicate == '*' && issa(val, 'Array') && !is_blank?(path)
30
29
  val = val.map {|item| unwind_path(item, path)}
31
30
  predicate = nil
32
- elsif !blank?(path) && issa(val, 'Hash')
31
+ elsif !is_blank?(path) && issa(val, 'Hash')
33
32
  val = unwind_path(val, path)
34
33
  end
35
34
  [val, predicate]
@@ -49,7 +48,7 @@ module HashAtPath
49
48
  end
50
49
 
51
50
  # Stolen from activesupport/lib/active_support/core_ext/object/blank.rb
52
- def blank?(object)
51
+ def is_blank?(object)
53
52
  object.respond_to?(:empty?) ? !!object.empty? : !object
54
53
  end
55
54
  end
@@ -1,24 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HashAtPath
2
4
  class Path
3
5
  class << self
4
6
  def parse(path_string)
5
7
  path_string = replace_predicates(path_string)
6
- vals = extract_path_data(path_string)
8
+ extract_path_data(path_string)
7
9
  end
8
10
 
9
11
  def replace_predicates(path_string)
10
- path_string.gsub!(/first\(\)/, "0")
11
- path_string.gsub!(/last\(\)/, "-1")
12
+ path_string = path_string.gsub(/first\(\)/, '0')
13
+ path_string = path_string.gsub(/last\(\)/, '-1')
12
14
  path_string
13
15
  end
14
16
 
15
17
  # Extracts paths and predicates from the provide full path
16
18
  def extract_path_data(path_string)
17
19
  results = array_wrap(path_string.scan(/([^\[]*)(\[)*(\d|\-\d|\*)*(\])*/i))
18
- results.map {|match| {:path => match[0], :predicate => match[2]}}
20
+ results.map { |match| { path: match[0], predicate: match[2] } }
19
21
  end
20
22
 
21
23
  private
24
+
22
25
  # Stolen from activesupport/lib/active_support/core_ext/array/wrap.rb
23
26
  def array_wrap(object)
24
27
  if object.nil?
@@ -31,4 +34,4 @@ module HashAtPath
31
34
  end
32
35
  end
33
36
  end
34
- end
37
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HashAtPath
2
- VERSION = "0.1.1"
4
+ VERSION = '0.1.6'
3
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_at_path
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - chadfennell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2020-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '10.0'
19
+ version: 12.3.3
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '10.0'
26
+ version: 12.3.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -71,15 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '2.1'
75
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
77
  - - ">="
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  requirements: []
81
- rubyforge_project:
82
- rubygems_version: 2.2.2
81
+ rubygems_version: 3.0.6
83
82
  signing_key:
84
83
  specification_version: 4
85
84
  summary: Extends Hash with xpath like syntax for retrieving hash values.