jazor 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "json"
4
+ gem "term-ansicolor"
4
5
 
5
6
  group :development do
6
7
  gem "rake"
data/Gemfile.lock CHANGED
@@ -12,6 +12,7 @@ GEM
12
12
  rspec-expectations (2.8.0)
13
13
  diff-lcs (~> 1.1.2)
14
14
  rspec-mocks (2.8.0)
15
+ term-ansicolor (1.0.7)
15
16
 
16
17
  PLATFORMS
17
18
  ruby
@@ -20,3 +21,4 @@ DEPENDENCIES
20
21
  json
21
22
  rake
22
23
  rspec
24
+ term-ansicolor
data/README.md CHANGED
@@ -68,6 +68,11 @@ scripts.
68
68
 
69
69
  ## Change Log
70
70
 
71
+ ### 0.1.5 (2012-03-23)
72
+
73
+ * Add --colorize option
74
+ * Bug fixes
75
+
71
76
  ### 0.1.4 (2012-03-05)
72
77
 
73
78
  * Add --quirks-mode option
data/bin/jazor CHANGED
@@ -8,6 +8,7 @@ require "jazor"
8
8
 
9
9
  options = {
10
10
  :quirks_mode => false,
11
+ :colorize => false,
11
12
  :test => false,
12
13
  :rest_data => {},
13
14
  :rest_headers => {},
@@ -28,6 +29,10 @@ OptionParser.new do |opts|
28
29
  options[:rest_headers][key.strip] = value.strip
29
30
  end
30
31
 
32
+ opts.on("-c", "--colorize", "Colorize output") do |opt|
33
+ options[:colorize] = true
34
+ end
35
+
31
36
  opts.on("-t", "--test", "Enable expression testing") do |opt|
32
37
  options[:test] = true
33
38
  end
@@ -76,7 +81,7 @@ begin
76
81
  Jazor::LOG.debug("Reading JSON from STDIN")
77
82
  Jazor::parse(STDIN.read, parse_options)
78
83
  elsif !ARGV[0].nil?
79
- if ARGV[0] =~ URI::regexp
84
+ if ARGV[0] =~ /^#{URI::regexp}$/
80
85
  Jazor::LOG.debug("Reading JSON from URI: #{ARGV[0]}")
81
86
  Jazor::parse(Jazor::RestClient.send(options[:rest_request], ARGV.shift, options[:rest_headers], options[:rest_data]).body, parse_options)
82
87
  elsif File.readable?(ARGV[0])
@@ -108,7 +113,7 @@ begin
108
113
  end
109
114
  else
110
115
  if [Hash, Array].include?(result.class)
111
- puts JSON.pretty_generate(result)
116
+ puts options[:colorize] ? Jazor::colorize(JSON.pretty_generate(result)) : JSON.pretty_generate(result)
112
117
  elsif result.is_a?(String)
113
118
  puts "\"#{result}\""
114
119
  else
data/lib/jazor.rb CHANGED
@@ -6,12 +6,13 @@ require "logger"
6
6
  require "net/http"
7
7
  require "net/https"
8
8
  require "pp"
9
+ require "term/ansicolor"
9
10
  require "uri"
10
11
 
11
12
  module Jazor
12
13
 
13
14
  NAME = "jazor"
14
- VERSION = "0.1.4"
15
+ VERSION = "0.1.5"
15
16
  AUTHOR = "Michael Paul Thomas Conigliaro"
16
17
  AUTHOR_EMAIL = "mike [at] conigliaro [dot] org"
17
18
  DESCRIPTION = "Jazor (JSON razor) is a simple command line JSON parsing tool."
@@ -34,6 +35,15 @@ module Jazor
34
35
  result
35
36
  end
36
37
 
38
+ def self.colorize(input)
39
+ input = input.gsub(/"(.*)":/, "\\1:".bold) # Key
40
+ input = input.gsub(/"(#{URI::regexp})"/i, "\\1".magenta.underline) # URL
41
+ input = input.gsub(/"(.*)"/, "\"\\1\"".green) # String
42
+ input = input.gsub(/(\s+[-+]?\d*\.?\d+)(,?)$/, "\\1".cyan + "\\2") # Numeric
43
+ input = input.gsub(/(\s+(true|false))(,?)$/, "\\1".blue + "\\3") # Boolean
44
+ input = input.gsub(/(\s+null)(,?)$/, "\\1".red + "\\2") # Null
45
+ end
46
+
37
47
  class RestClient
38
48
  def self.method_missing(method, uri, headers={}, data={})
39
49
  uri_parsed = URI.parse(uri)
@@ -67,3 +77,7 @@ class Hash
67
77
  end
68
78
  end
69
79
  end
80
+
81
+ class String
82
+ include Term::ANSIColor
83
+ end
@@ -5,7 +5,7 @@ describe "Jazor lib" do
5
5
  @test_hash = JSON.parse(@test_file)
6
6
  end
7
7
 
8
- %w{String Integer Float TrueClass FalseClass Array}.each do |t|
8
+ %w{String Integer Float TrueClass FalseClass NilClass Array}.each do |t|
9
9
  it "parses #{t} values in the root object" do
10
10
  obj = Jazor::parse(@test_file)["test_#{t}"]
11
11
  obj.should be_a Kernel.const_get(t)
data/spec/test.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "test_String": "123",
3
+ "test_String_URL": "http://example.com",
3
4
  "test_Integer": 123,
4
5
  "test_Float": 0.123,
5
6
  "test_TrueClass": true,
6
7
  "test_FalseClass": false,
8
+ "test_Nilclass": null,
7
9
  "test_Array": [1, 2, 3]
8
10
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jazor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-06 00:00:00.000000000 Z
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &2153832180 !ruby/object:Gem::Requirement
16
+ requirement: &2152522020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153832180
24
+ version_requirements: *2152522020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &2153831560 !ruby/object:Gem::Requirement
27
+ requirement: &2152520240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2153831560
35
+ version_requirements: *2152520240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2153830560 !ruby/object:Gem::Requirement
38
+ requirement: &2152517740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153830560
46
+ version_requirements: *2152517740
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2153828820 !ruby/object:Gem::Requirement
49
+ requirement: &2152531100 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153828820
57
+ version_requirements: *2152531100
58
58
  description: Jazor (JSON razor) is a simple command line JSON parsing tool.
59
59
  email: mike [at] conigliaro [dot] org
60
60
  executables:
@@ -86,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  segments:
88
88
  - 0
89
- hash: 607493245767784991
89
+ hash: -2127171486780227476
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  none: false
92
92
  requirements: