Class: JsonChecker::CheckableFile

Inherits:
Object
  • Object
show all
Defined in:
lib/json_checker/checkable_file.rb

Direct Known Subclasses

JSONToCheck

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(representation) ⇒ CheckableFile

Returns a new instance of CheckableFile.



8
9
10
11
12
# File 'lib/json_checker/checkable_file.rb', line 8

def initialize(representation)
     @name = representation['name']
     @path = representation['path']
     @remotePath = representation['remote-path']
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/json_checker/checkable_file.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/json_checker/checkable_file.rb', line 6

def path
  @path
end

#remotePathObject (readonly)

Returns the value of attribute remotePath.



6
7
8
# File 'lib/json_checker/checkable_file.rb', line 6

def remotePath
  @remotePath
end

Class Method Details

.is_valid_representation?(representation) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/json_checker/checkable_file.rb', line 14

def self.is_valid_representation?(representation)
  json = JsonChecker::JSONFetcher.json_from_content(representation)
  unless json.nil?
      return (json.keys.include? 'name') && ((json.keys.include? 'path') || (json.keys.include? 'remote-path'))
  end
  return false
end

Instance Method Details

#get_contentObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/json_checker/checkable_file.rb', line 22

def get_content()
  if @path.nil? && @remotePath.nil?
    puts "[ERROR] path or remote-path not found"
    return nil
  end

  unless @content.nil?
    return @content
  end

  @content = @path.nil? ? JSONFetcher.json_from_url(@remotePath) : JSONFetcher.json_from_path(@path)

  return @content
end