Class: CC::Engine::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/engine/content.rb

Overview

Pulls data from our database of suggestions for a linter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(linter) ⇒ Content

Instantiates a piece of content for a linter

Examples:

CC::Engine::Content.new("AltText")

Parameters:

  • linter (String)

    the linter to read content for


14
15
16
# File 'lib/cc/engine/content.rb', line 14

def initialize(linter)
  @linter = linter
end

Instance Attribute Details

#linterString (readonly)

The linter to read content for

Examples:

CC::Engine::Content.new("AltText").linter  #=> "AltText"

Returns:

  • (String)

25
26
27
# File 'lib/cc/engine/content.rb', line 25

def linter
  @linter
end

Instance Method Details

#bodyString, NilClass

The suggestions for how to fix a given piece of lint

Examples:

CC::Engine::Content.new("AltText").body  #=> "..."

Returns:

  • (String, NilClass)

34
35
36
# File 'lib/cc/engine/content.rb', line 34

def body
  @body ||= (File.exist?(content_path) && File.read(content_path)) || nil
end

#empty?Boolean

Checks whether the content is empty

Examples:

CC::Engine::Content.new("AltText").empty?  #=> false

Returns:

  • (Boolean)

45
46
47
# File 'lib/cc/engine/content.rb', line 45

def empty?
  !body
end

#to_hHash

Converts the contents into a Hash

Examples:

CC::Engine::Content.new("AltText").to_h  #=> {body: "..."}

Returns:

  • (Hash)

56
57
58
# File 'lib/cc/engine/content.rb', line 56

def to_h
  { body: body }
end

#to_json(*args) ⇒ String

Converts the contents into a JSON document

Examples:

CC::Engine::Content.new("AltText").to_h  #=> '{"body": '...'}"

Returns:

  • (String)

    the contents matching the Code Climate spec for contents


67
68
69
# File 'lib/cc/engine/content.rb', line 67

def to_json(*args)
  to_h.to_json(*args)
end