ppy 0.0.1

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 (3) hide show
  1. data/bin/ppy +13 -0
  2. data/lib/ppy.rb +70 -0
  3. metadata +48 -0
data/bin/ppy ADDED
@@ -0,0 +1,13 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+ require 'ppy'
5
+
6
+ file = ARGV.first
7
+
8
+ abort 'No file argument provided.' if file.nil?
9
+ abort 'File does not exist.' unless File.exists?(file)
10
+ abort 'Directory provided, provide a file path instead.' if File.directory?(file)
11
+
12
+ yaml = YAML.load_file(file)
13
+ PrettyYaml.print(yaml)
data/lib/ppy.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'rainbow'
2
+
3
+ module PrettyYaml
4
+
5
+ extend self
6
+
7
+ # Prints the actual data.
8
+ def print(data, level = 0)
9
+ case data
10
+ when Hash
11
+ data.each do |key, value|
12
+ if value.is_a? Enumerable
13
+ string = "#{indent_string(level)}#{format_key(key)}:"
14
+
15
+ if value.empty?
16
+ puts string + ' ' + format_value('{ }')
17
+ else
18
+ puts string
19
+ print(value, level + 1)
20
+ end
21
+ else
22
+ puts "#{indent_string(level)}#{format_key(key)}: #{format_value(value)}"
23
+ end
24
+ end
25
+ when Array
26
+ data.each do |value|
27
+ if value.is_a? Enumerable
28
+ string = format_key "#{indent_string(level)}-"
29
+ if value.empty?
30
+ puts string + ' ' + format_value('[ ]')
31
+ else
32
+ puts string
33
+ print_yaml(value, level + 1)
34
+ end
35
+ else
36
+ puts "#{indent_string(level)}#{format_key('-')} #{format_value(value)}"
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # creates space indentation for a string, based on a level int.
43
+ def indent_string(level)
44
+ " " * level
45
+ end
46
+
47
+ # Formats the data key.
48
+ def format_key(key)
49
+ key.to_s.color(:yellow)
50
+ end
51
+
52
+ # Formats the data value.
53
+ def format_value(value)
54
+ case value
55
+ when Numeric
56
+ value.to_s.color(:cyan)
57
+ when String
58
+ value
59
+ when TrueClass
60
+ value.to_s.color(:green)
61
+ when FalseClass
62
+ value.to_s.color(:red)
63
+ when NilClass
64
+ value.to_s.color(:blue)
65
+ else
66
+ value
67
+ end
68
+ end
69
+
70
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ppy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Damian Lee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A helper tool to pretty print YAML data.
15
+ email: damiankloip@gmail.com
16
+ executables:
17
+ - ppy
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/ppy.rb
22
+ - bin/ppy
23
+ homepage: http://rubygems.org/gems/ppy
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.23
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: Pretty Print YAML
47
+ test_files: []
48
+ has_rdoc: