ppy 0.0.4 → 0.0.5

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.
Files changed (4) hide show
  1. data/bin/ppy +12 -3
  2. data/lib/ppy/nested_access.rb +2 -2
  3. data/lib/ppy.rb +4 -3
  4. metadata +1 -1
data/bin/ppy CHANGED
@@ -12,10 +12,19 @@ abort 'Directory provided, provide a file path instead.' if File.directory?(file
12
12
 
13
13
  yaml = YAML.load_file(file)
14
14
 
15
- # If the vine gem is installed, only output a nested value if one has been
16
- # provided as the second argument.
15
+ # Only output a nested value if one has been provided as the second argument.
17
16
  unless ARGV[1].nil?
18
- yaml = yaml.nested_access(ARGV[1])
17
+ require 'ppy/nested_access'
18
+ require 'optparse'
19
+
20
+ seperator = ENV['PPY_SEPERATOR'] || '.'
21
+
22
+ OptionParser.new do |opt|
23
+ opt.on('-s SEPERATOR', '--seperator SEPERATOR') { |s| seperator = s }
24
+ opt.parse!
25
+ end
26
+
27
+ yaml = yaml.nested_access(ARGV[1], seperator)
19
28
  end
20
29
 
21
30
  PrettyYaml.print(yaml)
@@ -1,9 +1,9 @@
1
1
 
2
2
  class Hash
3
3
 
4
- def nested_access(path)
4
+ def nested_access(path, seperator = '.')
5
5
  ret = self
6
- path.to_s.split('.').each do |p|
6
+ path.to_s.split(seperator).each do |p|
7
7
  if p.to_i.to_s == p
8
8
  ret = ret[p.to_i]
9
9
  elsif !ret[p.to_s].nil?
data/lib/ppy.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  require 'rainbow'
2
- require 'ppy/nested_access'
3
2
 
4
3
  module PrettyYaml
5
4
  extend self
6
5
 
6
+ INDENT = ' '
7
+
7
8
  # Prints the actual data.
8
9
  def print(data, level = 0)
9
10
  case data
@@ -30,7 +31,7 @@ module PrettyYaml
30
31
  puts string + ' ' + empty_value(value)
31
32
  else
32
33
  puts string
33
- print_yaml(value, level + 1)
34
+ print(value, level + 1)
34
35
  end
35
36
  else
36
37
  puts "#{indent_string(level)}#{format_key('-')} #{format_value(value)}"
@@ -43,7 +44,7 @@ module PrettyYaml
43
44
 
44
45
  # Creates space indentation for a string, based on a level int.
45
46
  def indent_string(level = 0)
46
- " " * level
47
+ INDENT * level
47
48
  end
48
49
 
49
50
  # Formats an empty_value.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: