Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract JSON parsing method.

  • Loading branch information...
commit 42eae4a6ac2026088d497fb42312c3a0bfe40b0b 1 parent 9c71e67
@georgebrock georgebrock authored
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/helpers/uri_extractor.rb
View
15 lib/helpers/uri_extractor.rb
@@ -1,8 +1,7 @@
class URIExtractor
def initialize(file_name)
@file_name = file_name
- contents = File.read(@file_name)
- @json = JSON.parse(contents)
+ @json = parse_json
end
def each(&block)
@@ -11,10 +10,6 @@ def each(&block)
private
- def uris
- @uris ||= extract_uris(@json)
- end
-
def extract_uris(source)
if source.is_a?(Hash)
extract_uris_from_hash(source)
@@ -38,4 +33,12 @@ def extract_uris_from_hash(hash)
def extract_uris_from_array(array)
array.map { |o| extract_uris(o) }.flatten
end
+
+ def parse_json
+ JSON.parse(File.read(@file_name))
+ end
+
+ def uris
+ @uris ||= extract_uris(@json)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.