Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

start skeleton for md file creation

  • Loading branch information...
commit 4921169703558d322f8805c4a111ed23e00bc265 1 parent 407408b
Mike Munroe authored March 18, 2013

Showing 1 changed file with 42 additions and 0 deletions. Show diff stats Hide diff stats

  1. 42  lib/helpers/md_creator.rb
42  lib/helpers/md_creator.rb
... ...
@@ -0,0 +1,42 @@
  1
+class JSONValidator
  2
+  def initialize(file_name)
  3
+    @file_name = file_name
  4
+    @contents = File.open(@file_name).read
  5
+  end
  6
+
  7
+  def run
  8
+    create_md_files
  9
+  end
  10
+
  11
+  private
  12
+
  13
+  def create_md_files
  14
+    if parse_json?
  15
+      print_progress_marker
  16
+      return true
  17
+    else
  18
+      print_error_message
  19
+      return false
  20
+    end
  21
+  end
  22
+
  23
+  def parse_json?
  24
+    begin
  25
+      parsed_data = JSON.parse(@contents)
  26
+      puts parsed_data
  27
+
  28
+      return true
  29
+    rescue Exception => e
  30
+      return false
  31
+    end
  32
+  end
  33
+
  34
+  def print_progress_marker
  35
+    print '.'
  36
+  end
  37
+
  38
+  def print_error_message
  39
+    puts "\nERROR: #{@file_name} is not valid JSON. Learn more:"
  40
+    puts "cat #{@file_name} | pbcopy; open http://jsonlint.com"
  41
+  end
  42
+end

0 notes on commit 4921169

Please sign in to comment.
Something went wrong with that request. Please try again.